npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cerebral-addons

v0.6.3

Published

An actions and factories utility belt for Cerebral

Downloads

70

Readme

cerebral-addons Build Status

Additional utilities for use with cerebral/operators

Usage

import and from 'cerebral-addons/and';
import merge from 'cerebral-addons/merge';

Getters/Setters

cerebral-operators supports custom getter and setter functions in place of strings. If either of these functions is detected to by async (indicated by the returning of a promise) then the addon must be marked as async in the chain and subsequently define success and error paths.

getters

A getter is a function that accepts the args passed to an action method and returns some value.

// getter should return a value or a promise which will later resolve to a value
[promise] getter(args)

Example

an example getter might get some data from the server:

// define the getter
function httpGet(url) {
  return function (args) {
    return new Promise(resolve => {
      getDataFromServer(url, function (err, data) {
        resolve(data)
      })
    })
  }
}

// use the getter
[
  copy(httpGet('/api/date.json'), 'state:date'), {
    success: [],
    error: []
  }
]

setters

A setter is a function that accepts the args passed to an action method and the value to set.

// if the setter returns a promise then the addon will wait for it to resolve before continuing
[promise] setter(args, value)

if the setter is async then the addon will also pass on the resolve value to the success chain

Example

an example setter might post some data to the server:

// define the setter
function httpPost(url) {
  return function (args, value) {
    return new Promise(resolve => {
      postDataToServer(url, value, function (err, data) {
        resolve(data) // response from server will be passed onto success chain
      })
    })
  }
}

// use the setter
[
  copy('state:date', httpPost('/api/date.json')), {
    success: [],
    error: []
  }
]

included getters

cerebral-addons includes the following getters

and

export default [
  when(and('state:firstCondition', 'input:otherCondition')), {
    true: [],
    false: []
  }
]

compose

Compose replaces all getters found in object given to the compose factory with the runtime values

Compose doesn't currently support async getters

export default [
  copy(compose({
    fromInput: get('input:value'),
    fromState: get('state:value')
  }), 'output:composed')
]

get

see compose

isEqual

export default [
  when(isEqual('state:firstValue', 'input:otherValue')), {
    true: [],
    false: []
  }
]

isDeepEqual

export default [
  when(isDeepEqual('state:firstValue', 'input:otherValue')), {
    true: [],
    false: []
  }
]

literal

export default [
  copy(literal('literal'), 'output:value')
]

not

export default [
  when(and('state:firstCondition', not('input:otherCondition'))), {
    true: [],
    false: []
  }
]

or

export default [
  when(or('state:firstCondition', 'input:otherCondition')), {
    true: [],
    false: []
  }
]

findWhere

copy(findWhere('state:users', { name: 'John' }), 'output:john')

pop

pop also modifies the array in the state

copy(pop('state:users'), 'output:lastUser')

shift

shift also modifies the array in the state

copy(shift('state:users'), 'output:firstUser')

Included setters

cerebral-addons includes the following setters

merge

copy('input:newData', merge('state:allData'))

push

copy('input:newUser', push('state:users'))

unshift

copy('input:newUser', unshift('state:users'))

Note on Adblockers

Some adblockers such as uBlock Origin may block access to pop.js during development. This can be resolved by turning off ad blocking for localhost or using webpack (or similar) for development. This shouldn't be an issue for production deployments if you are packaging your production dependencies in a combined .min.js.

Contribute

Fork repo

  • npm install
  • npm start runs dev mode which watches for changes and auto lints, tests and builds
  • npm test runs the tests
  • npm run lint lints the code
  • npm run build compiles es2015 to es5