AngularJS Store
v3.0.0
v3.0.0
  • Introduction
  • Installation
  • Tutorials
    • Setup a store
    • Get the current state
    • Update the state
    • Get notified on state changes
    • Stop from receiving notifications
  • API Reference
    • NgStore
    • copy
    • dispatch
    • hook
Powered by GitBook
On this page
  1. API Reference

dispatch

PreviouscopyNexthook

Last updated 6 years ago

Was this helpful?

CtrlK

Was this helpful?

Send an update to store.

@parameters

Name

Type

Description

action

string

Action label.

newState

object function

New state that will merge to current state. Exceeded properties are not restricted. If you use a function for this, it should be look like: function (state) {...} and must return a new state.

@return

Type

Description

undefined

Examples:

const store = new NgStore({foo: true});

// Get the latest value of foo
let foo = store.copy('foo');

// Toggle the foo from store
// {foo: false}
store

Another option for updating the state is using function as second parameter, we can now omit the code from line 4 on the first example because the current state is already on the argument list of callback function.

const store = new NgStore({foo: true});

// Toggle the foo from store
// {foo: false}
store.dispatch('TOGGLE_FOO', (state) => {
    return {foo: !state
.dispatch
(
'TOGGLE_FOO'
,
{foo
:
!
foo});
.foo};
});