Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**@flow*/
- import {assert} from 'chai'
- import {concat, event, events, init, project, select, append, remove, update, value} from '../src/index'
- describe('Big example', () => {
- it('quick test', () => {
- const
- TYPE_NOTIFICATION = 'TYPE_NOTIFICATION',
- TYPE_DELETE = 'TYPE_DELETE',
- TYPE_UPDATE = 'TYPE_UPDATE',
- event2 = {
- type: TYPE_NOTIFICATION,
- data: {
- type: TYPE_UPDATE,
- notifications: [
- {id: 0, read: false},
- {id: 1, read: true},
- {id: 3, read: false}
- ]
- }
- },
- event1 = {
- type: TYPE_NOTIFICATION,
- data: {
- type: TYPE_DELETE,
- notifications: [1,2,3]
- }
- },
- reducer = events(
- event(
- TYPE_NOTIFICATION,
- project(
- e => e.data,
- event(
- TYPE_DELETE,
- ({counter, list}, {notifications}) => {
- list = list.filter(item => notifications.indexOf(item.id) == -1)
- return {
- counter: list.filter(item => !item.read).length,
- list: list
- }
- }
- ),
- event(
- TYPE_UPDATE,
- (state) => {
- console.log('dfadasfasdf')
- return state
- },
- select('counter', (state, {notifications}) => state + notifications.filter(item => !item.read).length),
- select('list', (state, {notifications}) => [...state, ...notifications])
- )
- )
- ),
- init({
- counter: 0,
- list: []
- })
- ),
- initialState = reducer(undefined, {type: '@@point/INIT'}),
- stateWithNotifications = reducer(initialState, event2),
- stateAfterRemove = reducer(stateWithNotifications, event1)
- console.log(initialState, stateWithNotifications, stateAfterRemove)
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement