npm.io
1.0.3 • Published 5 years ago

temperjs-store

Licence
MIT
Version
1.0.3
Deps
1
Size
74 kB
Vulns
5
Weekly
0

Temper Store · GitHub license

Table of contents

Installation

Using npm:

npm install temperjs-store

Using yarn:

yarn add temperjs-store
Introduction

Temper Store is a state container for JavaScript apps.

Usage
// using ES6 modules
import { storeActions } from 'temperjs-store'

// using CommonJS modules
const storeActions = require('temperjs-store').storeActions

storeActions.setTrait('traitPath', 'traitValue')
Actions

Temper Store exports an object with the following interface (more details on each action below):

interface StoreActions = {
  create(options?: StoreOptions): void
  getTrait<T>(path: string): T | undefined
  setTrait<T>(path: string, traitValue: SetterValue<T>): void
  subscribeToTrait<T>(
    path: string,
    callback: (traitValue: T | undefined) => void,
    defaultValue?: T
  ): Subscription | undefined
  destroy(): void
}
create

Creates the global store object.

getTrait

Returns the value of a Trait. Traits are globally shared units of state that components can subscribe to.

setTrait

Sets the value of a Trait.

subscribeToTrait

Subscribes a callback to a Trait and returns a Subscription object

destroy

Destroys the store.

Licence

MIT

Keywords