RunKit + npm: thesmo-redux-store

node v10.24.1
endpointsharetweet
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…