How to use the san-store.store.dispatch function in san-store

To help you get started, we’ve selected a few san-store examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github baidu / san-store / test / connect.san.spec.js View on Github external
it('components data should not infulence each other, and push item', done => {
        store.addAction('for-connect-5', email => {
            let builder = updateBuilder().push('persons[0].emails', email);
            return builder;
        });

        let MyComponent = connect.san({
            name: 'persons[0].name',
            emails: 'persons[0].emails'
        })(
            san.defineComponent({
                template: '<dl><dt title="{{name}}">{{name}}</dt><dd title="{{email}}">{{email}}</dd></dl>'
            })
        );

        store.dispatch('for-connect-persons', [
            {name: 'erik', emails: ['erik168@163.com', 'errorrik@gmail.com']}
        ]);

        let wrap = document.createElement('div');
        document.body.appendChild(wrap);

        let myComponent1 = new MyComponent();
        myComponent1.attach(wrap);
        let myComponent2 = new MyComponent();
        myComponent2.attach(wrap);

        let dts = wrap.getElementsByTagName('dt');
        let dds = wrap.getElementsByTagName('dd');
        expect(dts.length).toBe(2);
        expect(dds.length).toBe(4);
        expect(dts[0].title).toBe('erik');
github ecomfe / san-realworld-app / test / unit / common / action.spec.js View on Github external
it('set errors and clear errors', () => {
    store.dispatch(Types.ERRORS_SET, {title: 'one'});

    let errors = store.getState('errors');
    expect(errors.length).toBe(1);
    expect(errors[0]).toBe('title one');

    store.dispatch(Types.ERRORS_CLEAR);
    expect(store.getState('errors') == null).toBeTruthy();
  });
});
github ecomfe / san-realworld-app / test / unit / common / action.spec.js View on Github external
it('set errors and clear errors', () => {
    store.dispatch(Types.ERRORS_SET, {title: 'one'});

    let errors = store.getState('errors');
    expect(errors.length).toBe(1);
    expect(errors[0]).toBe('title one');

    store.dispatch(Types.ERRORS_CLEAR);
    expect(store.getState('errors') == null).toBeTruthy();
  });
});
github ecomfe / san-realworld-app / test / unit / article / action.spec.js View on Github external
it('fetch list', done => {
    let fetchPromise = store.dispatch(Types.FETCH);

    expect(store.getState('articlesLoading')).toBeTruthy();

    fetchPromise.then(() => {
        expect(store.getState('articlesLoading')).toBeFalsy();
        expect(store.getState('articleCount')).toBe(500);
        expect(store.getState('articlePageCount') >= store.getState('articleCount') / Conf.PAGE_SIZE).toBeTruthy();
        expect(store.getState('articles') instanceof Array).toBeTruthy();

        done();
    });


  });
});
github baidu / san-store / test / connect.san.spec.js View on Github external
beforeEach(done => {
        store.dispatch('reset-for-connect');
        setTimeout(done, 1);
    });
github baidu / san-store / test / connect.san.spec.js View on Github external
}
        })(
            san.defineComponent({
                template: '<u title="{{name}}-{{email}}">{{name}}-{{email}}</u>'
            })
        );

        let myComponent = new MyComponent();
        let wrap = document.createElement('div');
        document.body.appendChild(wrap);
        myComponent.attach(wrap);

        let u = wrap.getElementsByTagName('u')[0];
        expect(u.title).toBe('errorrik-errorrik@gmail.com');

        store.dispatch('for-connect-2', {
            name: 'erik',
            email: 'erik@gmail.com'
        });

        san.nextTick(() =&gt; {
            let u = wrap.getElementsByTagName('u')[0];
            expect(u.title).toBe('erik-erik@gmail.com');

            myComponent.dispose();
            document.body.removeChild(wrap);
            done();
        });
    });
github baidu / san-store / test / connect.san.spec.js View on Github external
let myComponent2 = new MyComponent();
        myComponent2.attach(wrap);

        let dts = wrap.getElementsByTagName('dt');
        let dds = wrap.getElementsByTagName('dd');
        expect(dts.length).toBe(2);
        expect(dds.length).toBe(4);
        expect(dts[0].title).toBe('erik');
        expect(dts[1].title).toBe('erik');

        expect(dds[0].title).toBe('erik168@163.com');
        expect(dds[1].title).toBe('errorrik@gmail.com');
        expect(dds[2].title).toBe('erik168@163.com');
        expect(dds[3].title).toBe('errorrik@gmail.com');

        store.dispatch('for-connect-6', 'erik168@163.com');

        san.nextTick(() => {
            let dts = wrap.getElementsByTagName('dt');
            let dds = wrap.getElementsByTagName('dd');
            expect(dts.length).toBe(2);
            expect(dds.length).toBe(2);

            expect(dds[0].title).toBe('errorrik@gmail.com');
            expect(dds[1].title).toBe('errorrik@gmail.com');

            myComponent2.data.push('person.emails', 'erik@erik.com');
            san.nextTick(() => {
                let dts = wrap.getElementsByTagName('dt');
                let dds = wrap.getElementsByTagName('dd');
                expect(dts.length).toBe(2);
                expect(dds.length).toBe(3);
github baidu / san-store / test / connect.san.spec.js View on Github external
email: 'emails[0]'
        })(
            san.defineComponent({
                template: '<u title="{{name}}-{{email}}">{{name}}-{{email}}</u>'
            })
        );

        let myComponent = new MyComponent();
        let wrap = document.createElement('div');
        document.body.appendChild(wrap);
        myComponent.attach(wrap);

        let u = wrap.getElementsByTagName('u')[0];
        expect(u.title).toBe('errorrik-errorrik@gmail.com');

        store.dispatch('for-connect-1', {
            name: 'erik',
            email: 'erik@gmail.com'
        });

        san.nextTick(() =&gt; {
            let u = wrap.getElementsByTagName('u')[0];
            expect(u.title).toBe('erik-erik@gmail.com');

            myComponent.dispose();
            document.body.removeChild(wrap);
            done();
        });
    });
github baidu / san-store / test / connect.san.spec.js View on Github external
expect(MyComponent === RawComponent).toBeFalsy();

        
        let wrap = document.createElement('div');
        document.body.appendChild(wrap);

        let myComponent = new RawComponent();
        myComponent.attach(wrap);

        let myComponent2 = new MyComponent();
        myComponent2.attach(wrap);

        expect(myComponent.el.title).toBe('efe-ecomfe@gmail.com');
        expect(myComponent2.el.title).toBe('errorrik-errorrik@gmail.com');

        store.dispatch('for-connect-9', {
            name: 'erik',
            email: 'erik@gmail.com'
        });

        myComponent.data.set('name', 'err');
        myComponent.data.set('email', 'errorrik@gmail.com');

        san.nextTick(() => {
            expect(myComponent.el.title).toBe('err-errorrik@gmail.com');
            expect(myComponent2.el.title).toBe('erik-erik@gmail.com');

            myComponent.dispose();
            myComponent2.dispose();
            document.body.removeChild(wrap);
            done();
        });
github ecomfe / san-realworld-app / src / common / action.js View on Github external
return function ({data}) {
        if (data.errors) {
            store.dispatch(Types.ERRORS_SET, data.errors);
        }
        else if (typeof fn === 'function'){
            fn(data);
        }
            
        return data;
    };
}

san-store

Application State Management for San

MIT
Latest version published 2 months ago

Package Health Score

76 / 100
Full package analysis