joyent-portal/legacy/spikes/fuzzy-search/react-selectize-stateless/src/actions.js
Sérgio Ramos 8295bd6882 chore: initial lerna setup
this shall be a progressive process
2017-05-25 10:56:50 +01:00

44 lines
895 B
JavaScript

const buildArray = require('build-array');
const delay = require('delay');
const faker = require('faker');
const actions = {
'FETCH': (state, action) => {
return {
...state,
items: (state.items || []).concat(action.payload)
};
}
};
const fetch = () => (dispatch, getState) => {
return dispatch({
type: 'FETCH',
payload: () => {
// debugger
const {
items = []
} = getState();
return buildArray(200).map((v, i) => {
const id = items.length + i;
return {
id,
name: faker.name.firstName(),
meta: `${faker.name.firstName()}|${faker.random.number()}`,
key: faker.image.imageUrl()
};
});
}
});
};
module.exports = (state, action) => {
return actions[action.type]
? actions[action.type](state, action)
: state;
};
module.exports.fetch = fetch;