Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobx observer pattern support

Tags:

mobx

hyperhtml

Mobx offers observer package which is only compatible with react, it makes it known to the store that data is being used and will rerun component on change. How do you replicate mobx observer support?

like image 393
janat08 Avatar asked Jul 18 '26 21:07

janat08


1 Answers

Mobx observers can be used like this:

@observable
name = 'bob'

function render( n ){ return (`<div>Hello ${n}</div>`) }

autorun( () =>{
    document.getEelementById('baseOfApp').innerHTML = render( name )
})

As name changes the function passed to autorun will be re-run. In this code react and mobx-react are not being used.

like image 173
Brian C. Avatar answered Jul 21 '26 16:07

Brian C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!