Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: thesmo-redux-store
node v10.24.1
endpoint
share
tweet
const { getStore } = require("thesmo-redux-store"); const store = getStore({}); const dataNode = "data"; const itemsNode = [dataNode, "items"]; const paginationNode = "pagination"; const pagesCount = [paginationNode, "count"]; const pageSize = 20; store.bindNodes({ rule: (newSeedValue) => { const { length } = newSeedValue; return () => Math.ceil(length / pageSize); }, seedPath: itemsNode, targetPath: pagesCount }); store.registrateNodeListener({ listener: (nodePath) => { const paginationInfo = store.obtain({ nodePath: paginationNode }); const paginationInfoAsJSON = JSON.stringify(paginationInfo); const nodePathAsString = nodePath.join("."); console.log( `New pagination info - ${paginationInfoAsJSON}, ` + `"${nodePathAsString}" node was updated` ); }, nodePath: paginationNode, isSpreading: true }); store.update({ calcField: () => new Array(100), nodePath: itemsNode }); store.update({ calcField: (x) => x.concat(new Array(50)), nodePath: itemsNode });
Created from: https://npm.runkit.com/thesmo-redux-store
Loading…
Clone and edit this document