npm store chain
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.yml
README.md
index.js
package.json
test.js

README.md

Allow to bind data on a promise chain.

Build Status

// usage exemple
storeChain(fetch("http://ipinfo.io/json"))
  .set("ipInfo")
  .then(() => fs.openFileAsync("./path/to/data.json"))
  .then(JSON.parse)
  .set("data")
  .get(({ ipInfo, data }) => Object.assign(data, { ipInfo }))
  .then(JSON.stringify)
  .then(result => fs.writeFile("./path/to/new-data.json", result))
  .get(({ ipInfo }) => {
    console.log(ipInfo)
    console.log("save successfull.")
  });

// Promise.all for objects
storeChain.all({
    ipInfo: fetch("http://ipinfo.io/json"),
    data: fs.openFileAsync("./path/to/data.json")
      .then(JSON.parse)
  })
  .then({ ipInfo, data } => Object.assign(data, { ipInfo }))
  .then(JSON.stringify)
  .then(result => fs.writeFile("./path/to/new-data.json", result))
  // No more access to ipInfo here so can't log the results.


// Combine both :
storeChain({
    ipInfo: fetch("http://ipinfo.io/json"),
    data: fs.openFileAsync("./path/to/data.json")
      .then(JSON.parse)
  })
  .then({ ipInfo, data } => Object.assign(data, { ipInfo }))
  .then(JSON.stringify)
  .then(result => fs.writeFile("./path/to/new-data.json", result))
  .get(({ ipInfo }) => {
    console.log(ipInfo)
    console.log("save successfull.")
  })