How to use the san-store.Store 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.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 / 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');
github baidu / san-store / test / store.spec.js View on Github external
it('remove listener by unlisten method', () => {
        let store = new Store({
            initData: {
                name: 'errorrik',
                emails: ['errorrik@gmail.com']
            },
            actions: {
                change({name, email}) {
                    return updateBuilder().set('name', name).push('emails', email);
                }
            }
        });

        expect(store.getState().name).toBe('errorrik');
        expect(store.getState().emails.length).toBe(1);


        let fireTimes = 0;
github baidu / san-store / test / store.spec.js View on Github external
it('children action not done, action shouldnot be mark done', done => {
        let store = new Store({});

        expect(store.getState().list == null).toBeTruthy();


        store.addAction('fetchList', function (page, {getState, dispatch}) {
            dispatch('showLoading');
            dispatch('updateCurrentPage', page);
            expect(getState('currentPage')).toBe(page);

            return requestList(page).then(list => {
                expect(getState('currentPage')).toBe(page);

                if (getState('currentPage') === page) {
                    dispatch('sleep');
                    dispatch('hideLoading');
github baidu / san-store / test / store.spec.js View on Github external
it('init data by constructor', () => {
        let store = new Store({
            initData: {
                name: 'errorrik',
                emails: ['errorrik@gmail.com']
            }
        });

        expect(store.getState().name).toBe('errorrik');
        expect(store.getState().emails[0]).toBe('errorrik@gmail.com');
        expect(store.getState('name')).toBe('errorrik');
        expect(store.getState('emails[0]')).toBe('errorrik@gmail.com');
    });
github baidu / san-store / test / store.spec.js View on Github external
it('listenable', () => {
        let store = new Store({
            initData: {
                name: 'errorrik',
                emails: ['errorrik@gmail.com']
            },
            actions: {
                change({name, email}) {
                    return updateBuilder().set('name', name).push('emails', email);
                }
            }
        });

        expect(store.getState().name).toBe('errorrik');
        expect(store.getState().emails.length).toBe(1);


        let isChangeFired;
github baidu / san-store / test / store.spec.js View on Github external
it('can add action after store created by "addAction"', () => {
        let store = new Store({
            initData: {
                name: 'errorrik',
                emails: ['errorrik@gmail.com']
            }
        });

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

        store.addAction('changeName', name => updateBuilder().set('name', name));
        store.dispatch('changeName', 'erik');
        expect(store.getState().name).toBe('erik');
    });
github baidu / san-store / test / store.spec.js View on Github external
it('update depend on current state', () => {
        let store = new Store({
            initData: {
                name: 'errorrik',
                emails: ['errorrik@gmail.com']
            }
        });

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

        store.addAction('change', function (info, {getState}) {
            let builder = updateBuilder().set('name', info.name);

            if (!getState('emails[0]')) {
                builder = builder.push('emails', info.email);
            }
github baidu / san-store / test / store.spec.js View on Github external
it('dispatch async action, promise resolve value is unuseful', done => {
        let store = new Store({
            initData: {
                name: 'errorrik',
                emails: ['errorrik@gmail.com']
            }
        });

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

        store.addAction('changeName', function (name, {dispatch}) {
            return new Promise(function (resolve) {
                setTimeout(() => {
                    dispatch('setName', name);
                    resolve(updateBuilder().set('name', 'hello'));
                }, 200);
            });
github baidu / san-store / test / store.spec.js View on Github external
it('dispatch async action in action', done => {
        let store = new Store({});

        expect(store.getState().list == null).toBeTruthy();

        store.addAction('fetchList', function (payload, {dispatch, getState}) {
            dispatch('loadingState', true);

            return requestList().then(list => {
                dispatch('loadingState', false);

                expect(getState('loading')).not.toBeTruthy();
                expect(getActionInfo().done).not.toBeTruthy();
                dispatch('updateList', list);
            });
        });

        store.addAction('updateList', function (list) {

san-store

Application State Management for San

MIT
Latest version published 17 days ago

Package Health Score

79 / 100
Full package analysis