-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"pure" components #35
Comments
That is an interesting idea. I wonder if we could memoize the tagged template literal? So basically if the strings and expressions are the same, return the last generated element. Then we could do a isSameNode and avoid calling morphdom at all in The main problem with memoizing at the var one = yo`<div>hi</div>`
var two = yo`<div>hi</div>` Both would become the same node and would cause a lot of issues as Or maybe there is a different way we could notify I have no idea but sounds fun to play around with ideas. |
Oh yes, that is a problem. If we memorize at the yo-yo level maybe we could keep a counter that increments every |
Yeah, one of the downsides of the way the system is designed is that we can't have an equivalent to React's
I was wondering about that - maybe some efficient tree-hashing function that can traverse values, objects and arrays alike - pops out a single value and sets it in |
We could use merkle-trees: https://github.com/datproject/docs/blob/master/hyperdrive.md#merkle-trees (nb. edge of my understanding here, but this seems like it might be what is needed) |
I was thinking along the same lines as @yoshuawuyts. |
I dont know exactly how to approach it, but i always was hoping that there is some way to instead of passing "props", i would pass an "observable" and whenever there is new data, the observable has a reference to the exact locations in the DOM that need patching. Additionally, what I like about relay/graphql/falcor stuff is that it's possible to specify "data dependencies" inside the components. In case of netflix or facebook, the available data is what they offer, which makes it hard for a component to be used in a completely different context. But, what if an API specification that has to be fulfilled by a backend can be derived from a frontend made up of a bunch of components that specify their data needs automatically? So having something like: function MyComponent(props) {
return yo`<div>${props.name}</div>`
} would become something like function MyComponent(db) {
return yo`<div>${db.watch('name')}</div>`
} This It's of course a bit more complex. This would be useful as response to some user interaction. I tried myself on something that does what i try to describe above, but it's still too hard for me to do.
I like the idea, but i'm too clumsy to implement it elegantly. I'd be happy to get some feedback on the idea and whether you feel this approach makes sense at all or not - and what are your thoughts about something "observableish" in general. |
I like the idea of being able to specify data constraints within the views / elements comprising the view. Given that any view will always have a notion of "what" data they need, it would be cool to make it explicit without adding the "where" the data comes from. With the This should probably live as a function that wraps
This sounds like you're gearing towards a two-way binding solution, which is something that in practice has turned out to generate more complexity than one-way flows do. What use case you you're trying to solve with observables that cannot be done by a unidirectional approach? I feel they could just as well live at the root of the DOM tree, and flush down objects into a giant object that can in turn be accessed by the views (e.g. Sorry if I'm rambling a little, I think there's some real cool ideas in here! Does it make sense what I'm saying? |
DOM tree thing: lots of people seem to use something reduxish having a giant json and reducers following immutability stuff, no? The "immutability" thing to me seems like a performance optimization, so that something can traverse an object fast by checking for changed references. two way binding: core idea of the previous posts above: for example // main.js
// ...
var subDB = db.sub('./data/user2')
var mc = MyComponent(subDB)
// mycomponent.js
var imagesnap = require('imagesnap')
module.exports = MyComponent
function MyComponent(db) {
var selfie$ = db.writable('./selfie')
var name$ = db.readable('./name')
return yo`
<div onclick=${e => imagesnap().pipe(selfie$)}>
${name$}
</div>
`
} |
I'm really starting to love the patterns that are starting to fall out of this POC https://github.com/kristoferjoseph/dam-yo/blob/master/screens/todos-create.js The division now is looking like views that register for updates and components that are passed state and dispatch. I'm currently researching the smallest way to add data diffs ( think light weight immutable ) to add a shouldUpdate method. |
I'm not sure how much of this is within morphdom, hyperx or bel.
How do these modules handle multiple updates to a large dom heirarchy when very little changes? Does morphdom do any simple
===
comparisons of nodes? If so can we make rendering more efficient by memoizing returned values? e.g. experimenting withyo-yo
so far I am writing quite a lot of:And all this is composed into a complete page. If yo/bel/hyperx could memoize the returned values for each input of strings and values, then morphdom could do a simple
===
and save time maybe?Maybe this is happening already? One potential case is animations - I want to
yo.update()
the entire page 60 times a second with new values being passed down through the render heirarchy. Most pieces/components of the page don't actually use values, but my understanding is that currently each time a new DOM element would be built, and morphdom would do a deep compare?Would this be a significant saving? I'm thinking how to reduce both the cost of unnecessary calls of bel.createElement and unnecessary diff calculations.
The text was updated successfully, but these errors were encountered: