1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

refactor, also add boilerplate edition store, actions and container

This commit is contained in:
Tim Daubenschütz 2015-05-21 17:59:38 +02:00
parent 60d4ce8eaf
commit 9c21edf8c4
7 changed files with 95 additions and 4 deletions

View File

@ -0,0 +1,24 @@
import alt from '../alt';
import EditionListFetcher from '../fetchers/edition_list_fetcher.js';
class EditionListActions {
constructor() {
this.generateActions(
'updateEditionList'
);
}
fetchList() {
EditionListFetcher
.fetch()
.then((res) => {
this.actions.updateEditionList(res.pieces);
})
.catch((err) => {
console.log(err);
});
}
};
export default alt.createActions(EditionListActions);

View File

@ -1,4 +1,5 @@
import alt from '../alt'; import alt from '../alt';
import PieceListFetcher from '../fetchers/piece_list_fetcher'; import PieceListFetcher from '../fetchers/piece_list_fetcher';
@ -10,7 +11,8 @@ class PieceListActions {
} }
fetchList(page, pageSize, search, orderBy, orderAsc) { fetchList(page, pageSize, search, orderBy, orderAsc) {
PieceListFetcher.fetch(page, pageSize, search, orderBy, orderAsc) PieceListFetcher
.fetch(page, pageSize, search, orderBy, orderAsc)
.then((res) => { .then((res) => {
this.actions.updatePieceList({ this.actions.updatePieceList({
'itemList': res.pieces, 'itemList': res.pieces,

View File

@ -16,6 +16,7 @@ let TableItem = React.createClass({
}, },
render() { render() {
/** /**
* An element in the Table can have a certain display_type. * An element in the Table can have a certain display_type.
* A display_type is just * A display_type is just

View File

@ -0,0 +1,32 @@
import React from 'react';
import AltContainer from 'alt/AltContainer';
import EditionListStore from '../stores/edition_list_store';
import EditionListActions from '../actions/edition_list_actions';
import Table from './ascribe_table/table';
import TableItemText from './ascribe_table/table_item_text';
import TableColumnModel from '../models/table_column_model';
let EditionList = React.createClass({
getInitialState() {
return EditionListStore.getState();
},
componentDidMount() {
EditionListActions.fetchList();
},
render() {
return (
<AltContainer store={EditionListStore} actions={EditionListActions}>
</AltContainer>
);
}
});
export default EditionList;

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import Router from 'react-router';
import AltContainer from 'alt/AltContainer'; import AltContainer from 'alt/AltContainer';
import PieceListStore from '../stores/piece_list_store'; import PieceListStore from '../stores/piece_list_store';
@ -11,8 +10,6 @@ import TableItemText from './ascribe_table/table_item_text';
import TableColumnModel from '../models/table_column_model'; import TableColumnModel from '../models/table_column_model';
let Link = Router.Link;
let PieceList = React.createClass({ let PieceList = React.createClass({

View File

@ -0,0 +1,20 @@
import fetch from 'isomorphic-fetch';
import AppConstants from '../constants/application_constants';
let EditionListFetcher = {
/**
* Fetches a list of editions from the API.
*/
fetch() {
return fetch(AppConstants.baseUrl + 'pieces/', {
headers: {
'Authorization': 'Basic ' + AppConstants.debugCredentialBase64
}
}).then((res) => res.json());
}
};
export default EditionListFetcher;

View File

@ -0,0 +1,15 @@
import alt from '../alt';
import EditionsListActions from '../actions/edition_list_actions';
class EditionListStore {
constructor() {
this.itemList = [];
this.bindActions(EditionsListActions);
}
onUpdateEditionList(itemList) {
this.itemList = itemList;
}
};
export default alt.createStore(EditionListStore);