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

Unify output from tree events and cursor events #506

Open
Gby56 opened this issue Jun 26, 2018 · 2 comments
Open

Unify output from tree events and cursor events #506

Gby56 opened this issue Jun 26, 2018 · 2 comments

Comments

@Gby56
Copy link

Gby56 commented Jun 26, 2018

Hi !
I was playing around with the library and my use-case is using baobab on this stucture :

const test = {
    "model": {
        "name": "foo",
        "list1": [{
                "prop1": "hey"
            },
            {
                "prop1": "ho"
            }
        ],
        "list2": [{
                "prop2": "bye"
            },
            {
                "prop2": "seeya"
            }
        ]
    }
}

Let's create the tree like so
const tree = new Baobab(test);
If I attach my watcher on tree like so :

	tree.on('update', (e) => {
		const eventData = e.data;
	});

In eventData I get previous, currentData, AND paths, and transactions !

Is it possible to retrieve such info from a cursor set directly on a nested value ?, such as :

	const cursor = tree.select('model', 'list1');

In the first case, the transaction gives the actual path of the event, giving the index of the targeted object of an array
In the second case, we only get the path of the cursor, not the affected element in the cursor's array

Thanks ! :)

@Yomguithereal
Copy link
Owner

Indeed, the cursor event does not have the same precision but I think it was because the use case did not exist yet. What do you want to do with it at cursor level? Also I suspect this is thusly made because of performance reasons but I need to dig deep into the code to make sure of this.

@Gby56
Copy link
Author

Gby56 commented Jun 26, 2018

I would have liked to handle updates differently for each of these big arrays, to prevent from having a "firehose situation" when reading directly updates from the tree.
That way I don't have to write logic for dispatching each event to each handler, it would be just a matter of attaching to different levels of the tree (kind of a subtree in the end !) :)

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

2 participants