nestore beta
Nested-wildcard event-based data store and state management API
Easy to Use
Nestore was designed from the ground up to centralize state management and simplify UI updates
Eventful Pub / Sub
Avoid context wrapping, complicated selectors and unnecessary re-renders with event-based architecture
Centralized Logic
Centralized state and logic with two-way data-binding and in-store mutators and listeners
Create a Simple Store
Create your store with key/values and built-in mutators and listeners
import nestore from 'nestore'
const myStore = await nestore({
logged_in: false,
user_data: null,
login: async (nst, [user, password]) => {
const userData = await Users.findOne({ where: { user_name: user } })
nst.store.user_data = userData
nst.set('logged_in', true)
return userData
}
})
export default myStore
Register some Listeners
Setup some callbacks to listen for changes to anything in the store
import myStore from './myStore.js'
myStore.on('logged_in', ({ value }) => {
alert(value ? 'Logged in!' : 'Logged out!')
})
const user = await myStore.login('Alice', 'password1234')
Mutate the Store
Work with your store like a standard ESMap object to get, set and remove values
import myStore from './myStore.js'
let user = myStore.get('user_data.username')
myStore.set('user_data', null)
myStore.remove('user_data')
myStore.reset()
Connect to a DB
Register adapters to connect and sync with your preferred database
import nestore from 'nestore'
import createMongoAdapter from 'nestore-mongo-adapter'
const myStore = await nestore({
greeting: 'Hello, World!',
}, {
adapters: [
createMongoAdapter({
mongoUri: process.env.MONGO_URI,
namespace: 'my-mongo-adapter',
documentKey: 'my-doc-key',
})
]
})
Beta - PR's welcome!
Nestore is still in beta, contributions / issues / pull-requests are welcome!
// Repo: https://github.com/pratiqdev/nestore/
// Bugs: https://github.com/pratiqdev/nestore/issues
// NPM: https://npmjs.com/package/nestore
// Version: 0.0.47