Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Releases: SaltyAom/purple-tea

0.3 - Complete Control

07 Feb 01:14
506859d
Compare
Choose a tag to compare

One thing people like about state container, a complete control over the state. Not only that, an external plugin which handle thing easier by putting a middleware in which is now added to Purple Tea.

0.3, middleware is now released along side with list and model for conplete control over state flow.

  • Middleware
    Callback function to manipulate data from middleware.

    store.applyMiddleware((store, process))
  • Middleware - A complete control over state flow.

    store.applyMiddleware((state: PurpleTea["store"], process: PurpleTeaProcess) => {
      console.log(state, process)
    })

    process is a process name which flow through the pipe

    type PurpleTeaProcess = "create" | "get" | "update" | "set" | "subscribe"
  • 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", {
      amount: 0
    })
    store.model() // [
      {
        name: "sugar",
        store: { amount: 0 }
      }
    ]

Breaking Change

  • store.add() is now deprecate and replace with store.create() due to confusing name. It take same argument and same behavior.

Minor change

  • Better typescript support.
  • Better JSDoc support.
  • Fix some bug.

0.2 - Server side support!

05 Feb 07:24
Compare
Choose a tag to compare

0.2 Released

Server-side-rendering is a common approach for modern JavaScript app. With a lot of benefit and complete control SSR is quite popular among JavaScript developer.
Previously Purple Tea doesn't provided SSR supports out of the box which is quite annoyed by developers.

Introducing Purple Tea 0.2 - Server side support.
The layer of Purple Tea extend native DOM API which doesn't support on Node server-side. To fully supported it, we might have to re-written from ground up and thus lose benefit of light-weight state storage.
Instead we defer the function and invoke once arrived on client-side. This process is widely used and so called Hydration.

Breaking Change

  • Update no longer overwrite an entire storage.
let tea = new Store()

// Mutate storage data, doesn't overwrite existed value if new value is not provided.
tea.add("sugar", { amount: 0 })
tea.get("sugar") // { amount: 0 }

tea.update("sugar", { amount: 1 })
tea.get("sugar") // { amount: 1 }
  • Set is introduced to overwrite a storage's value.
let tea = new Store()

// Overwrite a storage. Store's value will be overwriten. It take `store name` and `value`.
tea.add("sugar", { ingredient: "sugar", amount: 0 })
tea.get("sugar") // { ingredient: "sugar", amount: 0 }

tea.set("sugar", { amount: 0 })
tea.get("sugar") // { amount: 0 }