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

behave-immutable

v0.1.9

Published

An immutable data store that keeps state history

Downloads

23

Readme

behave-immutable

An immutable data store that keeps state history

Codeship Status for behavejs/behave-immutable

In most cases when you want to update a model/store, you will also want access to it's previous states, in a lot of frameworks this is something you have to design on your own even though this is how a model should behave.

behave-immutable depends on Facebook's Immutable library under the hood, when you pull state from the stack it will return you an instance of Immutable.

Install

npm install --save behave-immutable

Usage


// anything passed to constructor will be set as first state
const immutable = new BehaveImmutable({ some: 'value' });

// setting state
immutable.set({ another: 'value' });
immutable.toJS(); // => { some: 'value', another: 'value' }
immutable.at(1).toJS(); // => { some: 'value' }

// resetting state
immutable.set({ another: 'value' }, { reset: true });
immutable.toJS(); // => { another: 'value' }
immutable.at(1).toJS(); // => { some: 'value' }


// replacing state
immutable.set({ another: 'value' }, { reset: true, replace: true });
immutable.toJS(); // => { another: 'value' }
immutable.at(1); // => undefined
immutable.count(); // => 1

// working with state from the stack
let currentState = immutable.get(); // => latest state

let removeLastState = immutable.pop(); // => latest state, removing from stack

let removeFirstState = immutable.shift(); // => first state, removing from stack

let atIndex = immutable.at(someIndex); // => copy of state at index, non-destructive

let range = immutable.range(start, end); // => array of states in range (including end index)

immutable.purge(); // => empties the stack

// sugar methods to transform latest state
immutable.toJS(); // => { some: 'value', another: 'value' }

immutable.toJSON(); // => { "some": "value", "another": "value" }

immutable.serialize(); // => "some=value&another=value"

Testing

To run the tests for behave-immutable simply run npm test

Release History

  • 0.1.0 Initial release
  • 0.1.1 Fixed improper encoding on serialize
  • 0.1.2 Added test instructions to readme
  • 0.1.3 Minor refactoring
  • 0.1.4 Fixed incorrect main file in package.json
  • 0.1.5 Added build badge
  • 0.1.6 More descriptive examples in readme
  • 0.1.7 Fixed errors in examples
  • 0.1.8 Fixed error when setting initial state
  • 0.1.9 Updated build to latest code