-
Notifications
You must be signed in to change notification settings - Fork 93
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
Add a TodoMVC example #28
Comments
i just started working on this 😄 |
@gliechtenstein should modifying cell.$components actually update the components? I'm not seeing that happen, and it is making rendering this list very difficult. |
@gliechtenstein right now i have _add(item) {
this._items.push(item);
this.$update(); // this call
return true;
},
_delete(item) {
const index = this._items.indexOf(item);
if (index !== -1) {
this._items.splice(index, 1);
this.$update(); // also this one
return true;
} else {
return false;
}
},
$init() {
this.$update();
},
$update() {
this.$components = this._items.map(i => todoItem(i));
},
also it looks like things like |
@devsnek only the attributes "declared" on the gene will auto-trigger Also here's a fiddle that may help: https://jsfiddle.net/zk6s1c3z/ Let me know if this fixes your problem! |
I know Object.observe() was removed from spec and Chrome although there are
some polyfills, but I think there was a DomObserver that's widely
implemented and can be used to monitor the newly added attributes...
El 30/06/2017 22:47, "gliechtenstein" <notifications@github.com> escribió:
… @devsnek <https://github.com/devsnek> only the attributes "declared" on
the gene will auto-trigger $update(). This means you need to have an
_items key defined somewhere on the gene object. Otherwise it won't
trigger. More on this over at https://github.com/intercellular/tutorial#
important
Also here's a fiddle that may help: https://jsfiddle.net/zk6s1c3z/
Let me know if this fixes your problem!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#28 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAgfvps3cq-FGL2Sh7yL4QI2H58g8E5Pks5sJV7hgaJpZM4N9kKZ>
.
|
@piranna yup we're using something similar to Cell maintains a proxy object using Also the explicit definition of variables is a feature not a bug, it's like how you declare public variables when defining classes to let the outside world know how to interact with the class. Hope this makes sense! |
@gliechtenstein i do have an _items array on the gene, sorry for leaving out of that snippet. |
@devsnek can you share a fiddle? Not the whole thing, but if you could isolate the problem in as few lines of code as possible.. |
@devsnek this is because you're trying to call these functions on regular objects. These gene objects are nothing more than a regular javascript object. Even after they get instantiated into a Cell element, nothing changes to This means when you call So, what would work is if you call
instead of this line But this brings up an interesting issue, I see what you were trying to do there, maybe we could come up with simpler ways of referencing generated cells instead of doing Lastly, I didn't understand your comment about the |
@gliechtenstein I was thinking about this over the last few days and while I don't have a fully formed thought but I do have some observations. First is that there appears to be three options for referencing child elements.
|
Wanted to add another option which in some ways is better because of an inversion of control. That is using something like Redux or insert n variations of Redux. Some of the key benefits are; having a single source of truth, subscriptions are context local to state tracking cells and there's no need to have an identification schema because it's pulling data rather than pushing. Now of course local to the component data can be pushed down or whatever there's lots of options once you get the main chunk of state you're subscribed to. This of course has the limitation listed in #118 where you need to unmount the subscription. |
@kingoftheknoll wow thanks for the thorough list of options. I like the "Final option" on your first comment. I also had some ideas along the same line of thought but I haven't been able to yet think of an approach I really like, but I have a feeling we're on the right track. I think some variation of this approach would be best since we can implement the reference while preserving the decentralized nature. Let me think about this some more and update the thread as I come up with some ideas even if they're rough. Please don't hesitate to share more ideas on this when you come up with them too. BTW just to clarify, the As for the redux idea, I think this can be something that can be built on top of Cell but doesn't necessarily have to be a built-in feature. In fact if we make this the default, it will break the decentralized nature of Cells because redux is a very centralized approach. I'm not saying that centralized approach is bad, and actually I think it's the easiest way to implement apps like todo list because these apps by nature are centralized (the TODO database is the single source of truth), but even then I think it would be ideal if the centralized approach can be built on top of a perfect decentralized solution. Hope this makes sense :) |
@gliechtenstein I agree that Redux like state management should be optional. I'm more saying it might be the most ergonomic thing because of the inversion of control. On the flip side, if one is to push data down the question because where does the responsibility of the mutations lie? Cell.js already has a split view on this issue. First choice using the DOM api to select and mutate elements. Second is to delegate to the Which leads me to the point I keep coming back to which is there needs to be a conceptual/api boundary, dare I say a component with an api wrapping both choices. Now as a FP guy I really like delegation to something to do the side effects but since we want to sit on the DOM (dumpster fire of mutable state) I think an actor model is probably the best interface. I don't think you should ever from the root of the DOM tree query down and start mutating stuff willy-nilly. Rather, I think messages should be sent to the inboxes of components where their can do mutations or delegate messages/mutations to their child components. Coming from Elixir, I think about this in terms of it's OTP process supervision trees. So from that world processes get a |
Slight correction to what I said before. You would put the mailbox on the Genotype not the DOM element. And registering an identifier would be pointing back at the Genotype's inbox. This also tickles my memory about how React and friends efficiently do updates on lists which is to give a unique id to each element in the list for fast targeted updates. That's not too different than what I'm proposing. Another way to think about a registry would be to not have a global registry but rather a registry local to your immediate parent registry. But that would mean you can only send messages up and down the dom tree not across it... maybe not a good idea then =) |
@kingoftheknoll just realized we're on a TODOMVC thread haha, I just created a separate ticket so we can leave this ticket alone. If anyone else is interested in this "centralized structure" discussion as well, please check out: #143 |
Created a basic TodoMVC. |
While it might feel dated, it actually illustrates the basic interplay between a lot of moving parts (persistence, aggregate values, view filter, etc), and is simple enough to fit in one file.
The text was updated successfully, but these errors were encountered: