Platform
Resources
Pricing
Sign in
Get started
Andrew Wooldridge
📜JavaScript developer. 🐲RPG fan. 📚Storyteller and 🕹game developer. 👨Father and Husband.
Workspace
Fork
Published
2 collections
By
Andrew Wooldridge
Edited
Apr 8, 2022
Insert cell
Insert cell
Surprise-Free State Management! Designed for React with functional components, but can also be used with other frameworks (or no framework at all.)
Insert cell
Statery
=
import
(
'https://cdn.skypack.dev/statery@0.5.4?min'
)
Insert cell
store
=
Statery
.
makeStore
(
{
counter
:
0
}
)
Insert cell
increment
=
(
)
=>
store
.
set
(
(
state
)
=>
(
{
counter
:
state
.
counter
+
1
}
)
)
Insert cell
{
while
(
true
)
{
const
counter
=
store
.
state
.
counter
const
retVal
=
html
`
<div> Counter: ${
counter
} </div>
<div> <button>Add</button> </div>
`
retVal
.
querySelector
(
'button'
)
.
addEventListener
(
'click'
,
(
)
=>
{
increment
(
)
;
}
)
;
await
Promises
.
delay
(
1000
)
;
yield
retVal
;
}
}
Insert cell
html
`<div>
Counter (old ) state subscribed <b class='cstate'>null</b>
</br>
New (upcoming) state <b class='nstate'></b>
</div>`
Insert cell
{
// ( changes, state )
const
listener
=
(
changes
,
{
counter
}
)
=>
{
console
.
log
(
"Changes:"
,
changes
)
document
.
querySelector
(
'.cstate'
)
.
innerHTML
=
counter
document
.
querySelector
(
'.nstate'
)
.
innerHTML
=
changes
.
counter
}
store
.
subscribe
(
listener
)
}
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Listed in...
Tips and Utilities
Andrew Wooldridge
Working Libraries
Andrew Wooldridge
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Statery
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
store
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
increment
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML