Replies: 8 comments
-
Hey 👋! Mind if I give this a try? I'm new to sinuous but I do know a bit of MobX |
Beta Was this translation helpful? Give feedback.
-
hey Arnold 👋, of course feel free to try it out. I'm happy to help if you have any questions. Thanks |
Beta Was this translation helpful? Give feedback.
-
Thanks! Yes, I do have questions as to how I could go about writing this 😁. I'm new to this so forgive me if I get the terminologies wrong. I read thru the docs and the api that you linked. Overall, I was able to get the mobx state to update when I ran it like this import { html } from 'sinuous';
import { autorun } from 'mobx';
import { state } from './store'
function List() {
autorun(() => console.log(state.items));
return html`
<div>${state.items}</div>
<button onclick=${ () => {state.items = 'make pancakes, get cheese'} }>Update</button>
`;
}
export default List; However, this will only work on devtools console. I can see that I can change maybe the |
Beta Was this translation helpful? Give feedback.
-
I added a basic working example here for the The other important api's that need to be converted are (possibly @mweststrate can quickly point it out? 🙇) One thing to keep in mind is that Sinuous doesn't do a traditional re-render where it executes the whole List function again. It only re-runs the closures in the template. <div>${() => state.items}</div>
<div>${() => boxExample.get()}</div> That's why there needs to be a closure or function reference. I had hoped |
Beta Was this translation helpful? Give feedback.
-
After reading your response, it got me thinking.. what if import { html } from 'sinuous'
import { autorun } from 'mobx'
import App from './App'
function renderApp (id) {
const mainApp = html`
<${App} />
`
document.getElementById(id).replaceChildren(mainApp)
}
document.addEventListener('DOMContentLoaded', () => {
autorun(() => {
renderApp('app')
})
}) Where it will re-render the whole DOM if any of the children modify a mobx state, but I don't think this would be the right way, just find this a bit interesting. Let me read thru the docs for |
Beta Was this translation helpful? Give feedback.
-
There's a lot of push in Sinuous and friends to have fine-grained updates since web frameworks try to touch the DOM as little as possible. Some take the VDOM diff approach, like React or Choo.js, which allows developers to write code that looks like it updates everything on every change, but still doesn't touch the DOM unless it has to. Frameworks that don't have a VDOM (like Sinuous, Solid, Surplus, Svelte) use the fine-grained update approach. There is no diffing. Instead, these frameworks want to know ahead of time the smallest regions of DOM to update and focus only on those. What you're proposing needs a different style of framework, since it would be very expensive in this model since re-rendering everything would touch all the DOM. |
Beta Was this translation helpful? Give feedback.
-
If think what you want to leverage MobX, the thing you want to achieve is that MobX runs the reactive closures in autorun, not the entire component (that is what it does in React, but the beauty of the sinuous model is that isn't needed) |
Beta Was this translation helpful? Give feedback.
-
@mweststrate that is true, I also don't see the need to try to have a "render" if mobx just runs in reactive closures. I was able to tweak @luwes code a bit and created a wrapper that can be used as a https://jsfiddle.net/fmdb48kL/ While this works, the problem I encountered was that |
Beta Was this translation helpful? Give feedback.
-
Would be really cool to see an integration with MobX.
This can be done via the internal API Sinuous exposes https://github.com/luwes/sinuous#internal-api
Beta Was this translation helpful? Give feedback.
All reactions