diff --git a/src/subscriptions.test.ts b/src/subscriptions.test.js similarity index 80% rename from src/subscriptions.test.ts rename to src/subscriptions.test.js index 682d0bc..eb1d779 100644 --- a/src/subscriptions.test.ts +++ b/src/subscriptions.test.js @@ -1,46 +1,50 @@ import tap from 'tap'; import Updux from '.'; -import { action, payload } from 'ts-action'; import u from '@yanick/updeep'; +tap.test( 'subscriptions', async() => { + const inc = action('inc'); -const set_double = action('set_double', payload()); +const set_copy = action('set_copy'); const dux = new Updux({ initial: { x: 0, - double: 0, + copy: 0, }, actions: { inc, }, - mutations: [ - [inc, payload => u({ x: x => x + 1 })], - [set_double, double => u({ double })], - ], + mutations: { + inc: payload => u({ x: x => x + 1 }), + set_copy: copy => u({ copy }), + }, }); dux.addSubscription(store => (state, unsubscribe) => { if (state.x > 2) return unsubscribe(); - store.dispatch(set_double(state.x * 2)); + store.dispatch(set_copy(state.x)); }); const store = dux.createStore(); store.dispatch(inc()); -tap.same(store.getState(), { x: 1, double: 2 }); +tap.same(store.getState(), { x: 1, copy: 1 }); store.dispatch(inc()); store.dispatch(inc()); -tap.same(store.getState(), { x: 3, double: 4 }, 'we unsubscribed'); +tap.same(store.getState(), { x: 3, copy: 2 }, 'we unsubscribed'); + + +} ); tap.test('subduxes subscriptions', async t => { const inc_top = action('inc_top'); const inc_bar = action('inc_bar'); - const transform_bar = action('transform_bar', payload()); + const transform_bar = action('transform_bar'); const bar = new Updux({ initial: 'a', @@ -79,7 +83,7 @@ tap.test('subduxes subscriptions', async t => { ], subscriptions: [ store => { - let previous: any; + let previous; return ({ count }) => { if (count !== previous) { previous = count;