temperjs-store
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

Package Sidebar

Install

npm i temperjs-store

Homepage

temperjs.org

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

76.1 kB

Total Files

13

Last publish

Collaborators

  • ktripaldi