2.0.3 • Published 8 years ago

store-chain v2.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

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.")
  })
2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.4

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago