Skip to content
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

Subscribing to model changes, modifying the model directly #11

Open
ncote opened this issue May 15, 2014 · 3 comments
Open

Subscribing to model changes, modifying the model directly #11

ncote opened this issue May 15, 2014 · 3 comments

Comments

@ncote
Copy link

ncote commented May 15, 2014

Hi there,

Great tree, love the keyboard action.

I'd like to implement two-way binding using my own data model. Is there a way to subscribe to changes to the tree's internal model? And will the view react if we mutate the model directly? I see the Controller::on function looks like it might be related to this, but am not too sure how to use it.

@jaredly
Copy link
Owner

jaredly commented May 15, 2014

The model does publish changes to listeners registered through
controller.on. there's not yet a way to refresh the data going into the
treed instance, however.

I'm actually adding first class support for a data store layer, so you can
add a restful backend (or any other kind).

What are you thinking of using it for?
On May 15, 2014 5:53 AM, "ncote" [email protected] wrote:

Hi there,

Great tree, love the keyboard action.

I'd like to implement two-way binding using my own data model. Is there a
way to subscribe to changes to the tree's internal model? And will the view
react if we mutate the model directly? I see the Controller::on function
looks like it might be related to this, but am not too sure how to use it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/11
.

@ncote
Copy link
Author

ncote commented May 15, 2014

Thanks for the quick response.

I was trying to two-way bind it to a Knockout model. My app uses Knockout throughout, so I thought it would be nice to subscribe to tree changes to update my Knockout model; and also pass in my Knockout model changes to the tree.

My model can be edited through multiple views, all visible simultaneously, and I'd like to keep everything nicely synched and not have to worry about restoring state. That being said, if I could figure out the current state of the tree (selected node, editing or not, opened/closed branches) I might just rebuild the entire tree and restore the state when changes happen in another view.

More directly related to Controller.on though: listeners are eventually called without any arguments, so I'm not too too sure how to determine what has changed.

/nc

@nbnotabene
Copy link

Very nice work!

I want the component to be able to fetch and save the json-tree from/to node/express server.

Any suggestions is welcomed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants