0.0.1-alpha.94 • Published 9 months ago

@arborjs/plugins v0.0.1-alpha.94

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Arbor Plugins

"Buy Me A Coffee"

Set of official plugins for @arborjs/store.

!WARNING We will most likely split this package and move each plugin into their own package in the future.

Installation

Via npm

npm install @arborjs/plugins

Or via yarn

yarn add @arborjs/plugins

Usage

Logger

Provides some logging information regarding mutations happening in the store.

!WARNING This plugin is experimental and will likely change in the near future.

import { Arbor } from "@arborjs/store"
import { Logger } from "@arborjs/plugins"

const store = new Arbor({
  count: 0,
})

store.use(new Logger("counter"))

LocalStorage

Persists your store data to the browser's local storage, keeping it up-to-date as mutations happen.

import { Arbor } from "@arborjs/store"
import { LocalStorage } from "@arborjs/plugins"

const store = new Arbor({
  count: 0,
})

store.use(new LocalStorage({ key: "apps.counter" }))

You can override the serialization and deserialization logic used to persist data to local storage and read from it. This is quite handy when defining custom types to represent your data model, you can resort to @arborjs/json to handle type-preserving serialization/deserialization logic:

import { Arbor } from "@arborjs/store"
import { LocalStorage } from "@arborjs/plugins"
import { stringify, parse } from "@arborjs/json"

import { Todo } from "../models/Todo"
import { TodoList } from "../models/TodoList"

const store = new Arbor(
  new TodoList(new Todo("Do the dishes"), new Todo("Walk the dogs"))
)

store.use(
  new LocalStorage({
    key: "apps.todos",
    deserialize: parse,
    serialize: stringify,
  })
)

Using @arborjs/json to handle serialization/deserialization means that your application state will be serialized and save into local storage with type information preserved so when deserialized, what you get back are instances of the types composing the state, rather than raw literal objects and arrays.

Custom Plugins

!WARNING The plugin system is currently being experimented with and its API may suffer adjustments in the near future. However, we feel like its public API is close to a stable state.

Implementing a plugin for Arbor stores is quite simple, all you have to do is provide an object that conforms to the Plugin type:

type Plugin<T extends object> = {
  configure(store: Store<T>): Promise<Unsubscribe>
}

When passing an instance of a plugin to Arbor#use, the store will call the plugin's configure method, passing itself as an argument and wait on the returned Promise to resolve.

The configure method is where the plugin performs the logic to connect itself to the store, usually by subscribing to store events and returning a Promise that resolves when the configuration process is completed.

The returned promise resolves to a unsubscribe function that can be called whenever the plugin needs to disconnect from the store. When the configuration fails, the promise should then be rejected.

Support This Project

"Buy Me A Coffee"

License

Arbor is MIT licensed.

0.0.1-alpha.94

9 months ago

0.0.1-alpha.93

10 months ago

0.0.1-alpha.92

12 months ago

0.0.1-alpha.91

12 months ago

0.0.1-alpha.89

1 year ago

0.0.1-alpha.88

1 year ago

0.0.1-alpha.87

1 year ago

0.0.1-alpha.90

1 year ago

0.0.1-alpha.86

1 year ago

0.0.1-alpha.83

1 year ago

0.0.1-alpha.84

1 year ago

0.0.1-alpha.81

2 years ago

0.0.1-alpha.82

2 years ago

0.0.1-alpha.67

2 years ago

0.0.1-alpha.66

2 years ago

0.0.1-alpha.68

2 years ago

0.0.1-alpha.65

2 years ago

0.0.1-alpha.80

2 years ago

0.0.1-alpha.61

2 years ago

0.0.1-alpha.60

2 years ago

0.0.1-alpha.56

2 years ago

0.0.1-alpha.55

2 years ago

0.0.1-alpha.58

2 years ago

0.0.1-alpha.57

2 years ago

0.0.1-alpha.59

2 years ago

0.0.1-alpha.50

2 years ago

0.0.1-alpha.51

2 years ago

0.0.1-alpha.54

2 years ago

0.0.1-alpha.53

2 years ago

0.0.1-alpha.49

2 years ago

0.0.1-alpha.48

2 years ago

0.0.1-alpha.47

2 years ago

0.0.1-alpha.45

3 years ago

0.0.1-alpha.44

3 years ago

0.0.1-alpha.46

3 years ago

0.0.1-alpha.43

3 years ago

0.0.1-alpha.42

3 years ago

0.0.1-alpha.41

3 years ago

0.0.1-alpha.40

3 years ago

0.0.1-alpha.39

3 years ago

0.0.1-alpha.34

3 years ago

0.0.1-alpha.33

3 years ago

0.0.1-alpha.36

3 years ago

0.0.1-alpha.35

3 years ago

0.0.1-alpha.38

3 years ago

0.0.1-alpha.37

3 years ago

0.0.1-alpha.32

3 years ago

0.0.1-alpha.31

3 years ago

0.0.1-alpha.30

3 years ago

0.0.1-alpha.23

3 years ago

0.0.1-alpha.22

3 years ago

0.0.1-alpha.25

3 years ago

0.0.1-alpha.24

3 years ago

0.0.1-alpha.26

3 years ago

0.0.1-alpha.29

3 years ago

0.0.1-alpha.28

3 years ago

0.0.1-alpha.21

3 years ago

0.0.1-alpha.8

4 years ago

0.0.1-alpha.20

3 years ago

0.0.1-alpha.9

4 years ago

0.0.1-alpha.6

4 years ago

0.0.1-alpha.12

4 years ago

0.0.1-alpha.11

4 years ago

0.0.1-alpha.14

4 years ago

0.0.1-alpha.13

4 years ago

0.0.1-alpha.16

3 years ago

0.0.1-alpha.15

3 years ago

0.0.1-alpha.18

3 years ago

0.0.1-alpha.17

3 years ago

0.0.1-alpha.10

4 years ago

0.0.1-alpha.19

3 years ago

0.0.1-alpha.4

4 years ago

0.0.1-alpha.5

4 years ago

0.0.1-alpha.3

4 years ago

0.0.1-alpha.1

4 years ago

0.0.1-alpha.0

4 years ago