Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including chainbuilder-save with all npm packages installed. Try it out:

require("chainbuilder/package.json"); // chainbuilder is a peer dependency. var chainbuilderSave = require("chainbuilder-save")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

chainbuilder-save v1.0.0

Chainbuilder mixin for saving/restoring values.

chainbuilder-save Build Status

A chainbuilder mixin for saving/restoring values.

Installation npm install chainbuilder chainbuilder-save --save

Usage

var chainBuilder = require('chainbuilder');

var myChain = chainBuilder({
  methods: {/* ... your methods ... */},
  mixins: [
    /* ... other mixins ... */
    require('chainbuilder-save')()
  ]
});

Example

myChain(2)
  .plus(1)
  .save('var1')           // Saves 3 to 'var1'
  .plus(5)
  .save('var2')           // Save 8 to 'var2'
  .injectSaved('var1')    // Value in the chain is now 3
  .plus(1)
  .end(function (err, result) {
    console.log(result);                // > 4
    console.log(this.getSaved('var1')); // > 3
    console.log(this.getSaved('var2')); // > 8
  });

Methods

require('chainbuilder-save')()

Init the mixin.

save(varName)

Save the previous result.

@param {String} varName a name for the variable (re-using a name will override the value).

injectSaved(varName)

Inject the saved value back into the chain.

@param {String} varName name of the variable to restore.

this.getSaved(varName) context method

Get a saved value from within a chainbuilder context (e.g. a tap, transform or end callback).

@param {String} varName name of the variable to get.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free