mirror of
https://github.com/yldio/copilot.git
synced 2024-12-04 17:10:05 +02:00
44 lines
895 B
JavaScript
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;
|