This module lets you to create components with "real states" that persist during parent's re-renders
Marko 3 has an unusual way to dal with states. When a parent re-render the getInitialState
function of the child component is called in the children and they lose their state.
This let you persist the state across re-renders.
npm install marko-real-state
Or
yarn add marko-real-state
const realState = require('../../lib');
// Notice the `defineComponent(` *`realState`* `({`
module.exports = require('marko-widgets').defineComponent(realState({
// This is called only once and it will
// override variables declared in getInitialState
// What this function returns will persist when
// the parent state is updated and the component has to re-render
// You can keep using this.setState as usual to update the state
getInitialRealState: function(input) {
var value = input.value || 0;
return {
value: value
};
},
...
git clone https://github.com/ccinelli/marko-real-state.git
cd marko-real-state
# Run with this: [or browser-refresh server.js]
node server.js
- Tests