observable
A function as representation of a trackable mutable value.
It's basically just a function
that can be called in 3 ways,
If an observable is called with no arguments f()
, it returns the current value.
If it is called with an argument f(value)
, it set that as the value.
var o =var v =//set the value//get the value
If an observable is called with another function, it calls that function with the new value, whenever the value changes.
v(function(v){
console.log('Was changed to', v)
})
And to stop being notifed of these changes, call the function that was returned
var stop = v(function(v){
console.log('Was changed to', v)
})
// then some time later
stop()
value
var o =var v =v
How is this demo updating in real-time like that?
It's because observable
is integrated into
hyperscript!
input, & transform
observe a input field, and transform it into different string. this transformation is a one way observable.
var o =var h =var yourName
Oh, wow! wasn't that easy! and we did a lot of things there!
- made hyper text that updated in realtime
- read from an input as you typed
- transformed user input
And there is many other cool things we can do to!
not
Invert a boolean observable
var o =var h =var _i i
Hmm, I wonder if we could couple two things interms of each other?
var o =var h =var _i =var _j =var i = oinput_i 'checked' 'change'var j = oinput_j 'checked' 'change'//just make i != j & j != io
compute
Compute a value from others, like a computed value in SQL.
var o =var h =var i j
hover & focus
var h =var o =
signal
Like observable except only update listeners when the value actually changes.
var s = signal
License
MIT