Purple Tea
Light-weight state container for JavaScript app.
Store which doesn't hurt.
Purple Tea is very light-weight state container for JavaScript app. It contain shared state for JavaScript create( to access on any piece of code.
Purple tea is inspired by Redux but with only a simple and handy logic. Under the hood, it use a simple collection of JavaScript API which supported since IE 9.
Purple Tea feature:
- A very light-weight storage: 0.6KB (gzipped).
- Very high performance operation.
- Middleware support.
- Readable error message, easier to debug.
- As simple as LocalStorage.
- Get realtime storage change.
- TypeScript support.
- Support on every browser even IE 10.
Readable error
One thing people most hate about, unreadable error
by human. It's very annoying yet not productive to anyone.
Purple tea error is readable by human and suggested a way to resolve.
let tea = // Create "sugar" store with initial value of { amount: 0 } tea // { amount: 0 }tea // sugar is already existed.
A simple way to create store
Purple Tea is very easy to be created, maintained, and debugged. It's just a collection of simple API under the hood.
Create Store
Let's create a simple store with Purple Tea.
Purple Tea is created with class to contain reusable collection of function.
let tea =
create()
will handle storage creation. It require name
and initial storage value
.
let tea = tea
This will create a store name "sugar" with initial value of { amount: 0 }
.
Get data
get()
is introduced here, to retrieve data in the storage.
let tea = tea tea // { amount: 0 }teaamount // 0
If you get data from storage which isn't existed, it'll return error.
let tea = tea // sugar isn't existed. Please create it with create("sugar") teatea // { amount: 0 } tea // salt isn't existed. Please create it with create("sugar")
Update store
Mutate storage data, doesn't overwrite existed value if new value is not provided.
let tea = teatea // { amount: 0 } teatea // { amount: 1 }
Set store
Overwrite a storage. Store's value will be overwriten. It take store name
and value
.
let tea = teatea // { ingredient: "sugar", amount: 0 } teatea // { amount: 0 }
Subscribe to the storage
Purple tea is able to subscribe to the storage change in real-time.
let tea = tea // Trigger when store is updated.tea tea // Support multiple listener at once.tea
Middleware
A function which invoked before operation succeed. Mutate store data is recommended here.
let tea = tea tea
-
list - Get every store name.
store.create"sugar",store.list // ["sugar"] -
model - Get collection of store's model. An equivalent to
Object.entries()
store.create"sugar",store.model // []