92green / enty

Normalized State Management
MIT License
6 stars 1 forks source link

enty state v2 #162

Closed allanhortle closed 4 years ago

allanhortle commented 4 years ago

This goes after the schema changes in #161

Store replaces EntityApi and is a class with methods to normalize data and listen for changes. There are now two paths you can take. Plain old update will just normalize new things into the store. Then you can pull an entity out by id with getEntity (I might add the ability to get a whole set of entities out at once). The other path is the more familiar request based api updateRequest and getRequest this handles async stuff (and later caching/ttl).

const store = new EntityStore({
    schema: MainSchema,
    api: {
        // usual api stuff
    }
})

Highlights

store.update() // NEW: normalize anything into the store using the main schema
store.updateRequest() // normalize a request into the store (similar to the existing way)
store.getEntity() // NEW: whip any entity out of the store
store.getRequest() // get a request out of the store
store.subscribe() // NEW: subscribe to changes in the store
store.api // Same as the old export from EntityApi