How to use san-store - 10 common examples

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.createConnector.spec.js View on Github external
describe('Connect createConnector component', () => {
    const store = new Store();
    store.addAction('reset-for-connect', () => {
        let resetBuilder = updateBuilder()
            .set('name', 'errorrik')
            .set('emails', ['errorrik@gmail.com']);

        return resetBuilder;
    });

    beforeEach(done => {
        store.dispatch('reset-for-connect');
        setTimeout(done, 1);
    });
    // 手动连接自己声明的store
    const manualConnect = connect.createConnector(store);

    it('data should be ready when component init', () => {
github baidu / san-store / test / connect.createConnector.spec.js View on Github external
describe('Connect createConnector component', () => {
    const store = new Store();
    store.addAction('reset-for-connect', () => {
        let resetBuilder = updateBuilder()
            .set('name', 'errorrik')
            .set('emails', ['errorrik@gmail.com']);

        return resetBuilder;
    });

    beforeEach(done => {
        store.dispatch('reset-for-connect');
        setTimeout(done, 1);
    });
    // 手动连接自己声明的store
    const manualConnect = connect.createConnector(store);

    it('data should be ready when component init', () => {
        let MyComponent = manualConnect({
            name: 'name',
            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');
github baidu / san-store / test / connect.san.spec.js View on Github external
it('dispatch action method should connect to component "actions" member, object mapActions', done => {
        store.addAction('for-connect-3', payload => {
            let builder = updateBuilder()
                .set('name', payload.name)
                .set('emails[0]', payload.email);

            return builder;
        });

        let MyComponent = connect.san(
            {
                name: 'name',
                email: 'emails[0]'
            },
            {
                updateInfo: 'for-connect-3'
            }
        )(
github baidu / san-store / test / connect.san.spec.js View on Github external
it('async action should return Promise', done => {
        store.addAction('for-connect-7', (name, {dispatch}) => {
            return new Promise(function (resolve) {
                setTimeout(() => {
                    dispatch('for-connect-8', name);
                    resolve();
                }, 100);
            });
        });

        store.addAction('for-connect-8', name => {
            return updateBuilder().set('forConnect7', name);
        });

        let MyComponent = connect.san(
            {name: 'forConnect7'},
            {change: 'for-connect-7'}
        )(
github baidu / san-store / test / connect.san.spec.js View on Github external
it('component data should be update when store data change, function mapStates item', done =&gt; {
        store.addAction('for-connect-2', payload =&gt; {
            let builder = updateBuilder()
                .set('name', payload.name)
                .set('emails[0]', payload.email);

            return builder;
        });

        let MyComponent = connect.san({
            name: 'name',
            email: state =&gt; {
                return state.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];
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 =&gt; {
        store.addAction('for-connect-5', email =&gt; {
            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 / store.spec.js View on Github external
it('can data change by dispatch action', () => {
        let store = new Store({
            initData: {
                name: 'errorrik',
                emails: ['errorrik@gmail.com']
            },
            actions: {
                changeName(name) {
                    return updateBuilder().set('name', name);
                }
            }
        });

        expect(store.getState().name).toBe('errorrik');
        expect(store.getState().emails[0]).toBe('errorrik@gmail.com');

        store.dispatch('changeName', 'erik');
        expect(store.getState().name).toBe('erik');

san-store

Application State Management for San

MIT
Latest version published 2 months ago

Package Health Score

76 / 100
Full package analysis