51 lines
1007 B
JavaScript
51 lines
1007 B
JavaScript
import { test } from 'tap';
|
|
import u from 'updeep';
|
|
import add from 'lodash/fp/add.js';
|
|
|
|
import { Updux } from './index.js';
|
|
|
|
test('README.md', async (t) => {
|
|
const otherDux = new Updux({});
|
|
|
|
const dux = new Updux({
|
|
initial: {
|
|
counter: 0,
|
|
},
|
|
actions: {
|
|
inc: null,
|
|
},
|
|
subduxes: {
|
|
otherDux,
|
|
},
|
|
});
|
|
|
|
dux.setMutation('inc', (increment) => u({ counter: add(increment) }));
|
|
|
|
dux.addEffect('*', (api) => (next) => (action) => {
|
|
next(action);
|
|
});
|
|
|
|
const store = dux.createStore();
|
|
|
|
store.dispatch.inc(1);
|
|
|
|
t.equal(store.getState().counter, 1);
|
|
});
|
|
|
|
|
|
test('tutorial', async (t) => {
|
|
|
|
const todosDux = new Updux({
|
|
initial: {
|
|
next_id: 1,
|
|
todos: [],
|
|
}
|
|
});
|
|
|
|
todosDux.setAction( 'addTodo' );
|
|
todosDux.setAction( 'todoDone' );
|
|
|
|
t.same( todosDux.actions.addTodo('write tutorial') , { type: 'addTodo', payload: 'write tutorial' });
|
|
|
|
})
|