0.2.0 • Published 4 years ago
imba-auto-state v0.2.0
imba-auto-state
imba-auto-state is a super easy-to-use state management solution for imba
Install
Run this in your project root
npm install imba-auto-stateQuick Start: StatefulTag
- Import
StatefulTag
import { StatefulTag } from "imba-auto-state"- Simply create a tag that inherits from StatefulTag with a variable
stateattached, it must be an object.
import { StatefulTag } from "imba-auto-state"
tag App < StatefulTag
state = { count: 0 }
def render
<self>
<div>
<p> "Count: {state.count}"
<div>
<button @click=(state.count++)> "+"
<button @click=(state.count--)> "-"Changing any nested property of the state object, anywhere else in your codebase will ensure this component renders itself again.
Quick Start: Global State
Import
createAutoStatein astate.imbafileimport { createAutoState } from "imba-auto-state" ### we need to provide 2 things a `state` object, and a callback function to call whenever `state` changes ### const appState = createAutoState({counter: 0}, do imba.commit!) # now we can simply extend the global base element extend tag element get #state appStateNow just import
state.imbasomewhere, anywhere, in your project.
Changing any nested property of the state object, anywhere else in your codebase will call the provided callback. In this case, imba will schedule a re-render for the next frame.