-
Import Waos Js functions components on your project
import { PointState, clickEvent } from './waos.js';
-
Write your code HTML inside of waos id.
<main id="waos"> <!-- Your code --> </main>
-
Insert a state into your HTML document
<main id="waos"> <strong state="counter"> <!-- "counter" is the state name! --> </strong> </main>
-
Insert a click event into your HTML for change state
<button on-click="change-counter"> Change state +1 </button>
-
On your Javascript file use the functions exported from Waos Js
// Create a new point state const counter = new PointState("counter", 0); /* * PointState is the state * "counter" is the state name * "0" is state value */
-
You may change the state with "set" property from "counter" constant.
// This increment state value + 1 counter.set(prev => prev + 1)
-
Create a handlerEvent for your click event.
// Example of HandlerEvent for counter click event const handleCounter = () => counter.set(prev => prev + 1);
-
With ClickEvent from Waos Js you may change state value "counter".
/* * change-counter is the state attribute insterted in your * HTML document * Step 4 */ clickEvent('change-counter', handleCounter)
-
You also may change the state directly from clickEvent
/* * Example of ClickEvent * for counter click event */ clickEvent('change-counter', () => { counter.set(prev => prev + 1) })
-
Notifications
You must be signed in to change notification settings - Fork 0
This is a basic library for create states on vanilla js
Erickgiber/waos-js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
This is a basic library for create states on vanilla js
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published