Socket
Book a DemoInstallSign in
Socket

choo-shortcut

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

choo-shortcut

Shortcut access to parts of the state anywhere in your app

0.1.0
latest
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

choo-shortcut

Shortcut access to parts of the state anywhere in your app.

Useful to simulate "contexts", avoid passing down the state to hell. It's again a ridiculous little function.

Installation

npm i choo-shortcut

Example

// flowers-context.js
var createShortcut = require('choo-shortcut')

var shortcut = createShortcut(function (state, emitter) {
  return state.flowers
})

module.exports = shortcut.set
module.exports.getFlowers = shortcut.get

In your main file:

app.use(require('./flowers-context'))

Then anywhere in your app

var { getFlowers } = require('../flowers-context')

getFlowers()
// state.flowers that has been set somewhere

API

shortcut = createShortcut(reducer(state, emitter))

Creates a new shortcut (context store). reducer is a function which "reduces" the state to the part that should be stored. It gets the typical state and emitter of a Choo store.

shortcut.set(state, emitter)

The store that should be passed to app.use.

shortcut.get()

Returns the current value that's stored.

Keywords

choo

FAQs

Package last updated on 11 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.