How to use the san-store.store.addAction 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('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 / example / todos / src / category / action.js View on Github external
});

store.addAction('editCategory', function (payload) {
    return updateBuilder().set('categories[' + payload.index + ']', payload.category);
});

store.addAction('startAddCategory', function () {
    return updateBuilder()
        .set('addingCategory', {
            title: '',
            color: ''
        })
        .set('addingCategoryFinished', false);
});

store.addAction('submitAddCategory', function (category, {dispatch}) {
    return service.addCategory(category).then(addedCategory => {
        dispatch('addCategory', addedCategory);
    });
});

store.addAction('addCategory', function (category) {
    return updateBuilder()
        .push('categories', category)
        .set('addingCategoryFinished', true);
});
github ecomfe / san-realworld-app / src / article / action.js View on Github external
return updateBuilder().set('tags', data.tags);
});

store.addAction(Types.RESET, function () {
    return updateBuilder()
        .set('article', {
            author: {},
            title: "",
            description: "",
            body: "",
            tagList: []
        })
        .set('comments', []);
});

store.addAction(Types.GET, function (slug, {dispatch}) {
    return service.get(slug).then(({data}) => {
        dispatch(Types.SET, data.article);
    });
});

store.addAction(Types.SET, function (article) {
    return updateBuilder().set('article', article);
});

store.addAction(Types.SET_AUTHOR, function (author) {
    return updateBuilder().set('article.author', author);
});

store.addAction(Types.ADD_TAG, function (tag) {
    return updateBuilder().push('article.tagList', tag);
});
github ecomfe / san-realworld-app / src / article / action.js View on Github external
if (payload.favorited) {
            params.favorited = payload.favorited;
        }
    }

    dispatch(Types.FETCHING);
    return fetch(params).then(response => {
        dispatch(Types.FETCH_FILL, response.data);
    });
});

store.addAction(Types.FETCHING, function () {
    return updateBuilder().set('articlesLoading', true);
});

store.addAction(Types.FETCH_FILL, function ({articles, articlesCount}) {
    return updateBuilder()
        .set('articles', articles)
        .set('articleCount', articlesCount)
        .set('articlesLoading', false)
        .set('articlePageCount', Math.ceil(articlesCount / config.PAGE_SIZE));
});

store.addAction(Types.TAGS, function (payload, {dispatch}) {
    return service.tags().then(response => {
        dispatch(Types.TAGS_FILL, response.data);
    });
});

store.addAction(Types.TAGS_FILL, function (data) {
    return updateBuilder().set('tags', data.tags);
});
github baidu / san-store / example / todos / src / category / action.js View on Github external
let categories = getState('categories');

        let index = -1;
        categories.forEach((item, i) => {
            if (item.id === categoryId) {
                index = i;
            }
        });

        if (index >= 0) {
            dispatch('rmCategory', index);
        }
    });
});

store.addAction('rmCategory', function (index) {
    return updateBuilder().splice('categories', index, 1);
});

store.addAction('startEditCategory', function (category, {getState, dispatch}) {
    return service.editCategory(category).then(editedCategory => {
        let categories = getState('categories');

        let index = -1;
        categories.forEach((item, i) => {
            if (item.id === editedCategory.id) {
                index = i;
            }
        });

        if (index >= 0) {
            dispatch('editCategory', {index, category: editedCategory});
github ecomfe / san-realworld-app / src / article / action.js View on Github external
author: {},
            title: "",
            description: "",
            body: "",
            tagList: []
        })
        .set('comments', []);
});

store.addAction(Types.GET, function (slug, {dispatch}) {
    return service.get(slug).then(({data}) => {
        dispatch(Types.SET, data.article);
    });
});

store.addAction(Types.SET, function (article) {
    return updateBuilder().set('article', article);
});

store.addAction(Types.SET_AUTHOR, function (author) {
    return updateBuilder().set('article.author', author);
});

store.addAction(Types.ADD_TAG, function (tag) {
    return updateBuilder().push('article.tagList', tag);
});

store.addAction(Types.REMOVE_TAG, function (tag) {
    return updateBuilder().remove('article.tagList', tag);
});

store.addAction(Types.REMOVE, function (slug) {
github ecomfe / san-realworld-app / src / article / action.js View on Github external
store.addAction(Types.ADD_COMMENT, function (payload, {dispatch}) {
    return service.addComment(payload.slug, payload.comment)
        .then(() => {
            dispatch(Types.GET_COMMENTS, payload.slug);
        });
});

store.addAction(Types.GET_COMMENTS, function (slug, {dispatch}) {
    return service.getComments(slug).then(({data}) => {
        dispatch(Types.FILL_COMMENTS, data.comments);
    });
});


store.addAction(Types.FILL_COMMENTS, function (comments) {
    return updateBuilder().set('comments', comments);
});

store.addAction(Types.REMOVE_COMMENT, function (payload, {dispatch}) {
    return service.removeComment(payload.slug, payload.commentId)
        .then(() => {
            dispatch(Types.GET_COMMENTS, payload.slug);
        });
});

store.addAction(Types.ADD_FAVORITE, function (slug, {dispatch}) {
    return service.addFavorite(slug).then(
        ({data}) => {
            dispatch(Types.SET, data.article);
            dispatch(Types.SET_LIST_ITEM, data.article);
        }
github baidu / san-store / example / todos / src / todo / action.js View on Github external
return service.rmTodo(id).then(todoId => {
        let todos = getState('todos');
        let index = -1;
        todos.forEach((item, i) => {
            if (todoId == item.id) {
                index = i;
            }
        });

        if (index >= 0) {
            dispatch('rmTodo', index);
        }
    });
});

store.addAction('rmTodo', function (index) {
    return updateBuilder().splice('todos', index, 1);
});

store.addAction('startDoneTodo', function (id, {getState, dispatch}) {
    return service.doneTodo(id).then(todoId => {
        let todos = getState('todos');
        let index = -1;
        todos.forEach((item, i) => {
            if (todoId == item.id) {
                index = i;
            }
        });

        if (index >= 0) {
            dispatch('doneTodo', index);
        }
github ecomfe / san-realworld-app / src / article / action.js View on Github external
});
});


store.addAction(Types.FILL_COMMENTS, function (comments) {
    return updateBuilder().set('comments', comments);
});

store.addAction(Types.REMOVE_COMMENT, function (payload, {dispatch}) {
    return service.removeComment(payload.slug, payload.commentId)
        .then(() => {
            dispatch(Types.GET_COMMENTS, payload.slug);
        });
});

store.addAction(Types.ADD_FAVORITE, function (slug, {dispatch}) {
    return service.addFavorite(slug).then(
        ({data}) => {
            dispatch(Types.SET, data.article);
            dispatch(Types.SET_LIST_ITEM, data.article);
        }
    );
});

store.addAction(Types.REMOVE_FAVORITE, function (slug, {dispatch}) {
    return service.removeFavorite(slug).then(
        ({data}) => {
            dispatch(Types.SET, data.article);
            dispatch(Types.SET_LIST_ITEM, data.article);
        }
    );
});

san-store

Application State Management for San

MIT
Latest version published 1 year ago

Package Health Score

55 / 100
Full package analysis