Skip to main content

Update the Store

You can manually update/create values/keys externally using the set method or by updating the value directly. You can also update the entire store using either of these methods. Setting the value to null or undefined will not remove the key from the store.

import nst from './myStore.js'

nst.logged_in = false
nst.set('user_name', null)

Setting the value to null or undefined will not remove the key from the store, see usage/remove for more details.

nst.set('user_name', )
nst.set('user_name', null)
nst.set('user_name', undefined)

Transient updates

Update the stores properties or values directly to prevent events from being emitted. The store object is available as a root property on the store object.

import nst from './myStore.js'

nst.on('*', () => /* No events emitted */)

nst.store.super_secret.code = 98765
nst.store.newValue = 'abcd'

Update using Mutator Functions

Update the store using custom mutator functions for simplified updates. Mutator functions can take and return any value or arguments, or retrieve current values internally from the store object.

import nst from './myStore.js'

const result = await nst.login('username', 'password')
nst.sendMessage('Bob456', 'Hello Bob!')