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

Stable Queries #163

Open
cowboyd opened this issue Jul 25, 2018 · 3 comments
Open

Stable Queries #163

cowboyd opened this issue Jul 25, 2018 · 3 comments

Comments

@cowboyd
Copy link
Member

cowboyd commented Jul 25, 2018

Queries are achieved via computed properties. They are ways of collecting and viewing a set of microstates that are already defined within a given microstate. For example:

import { filter } from 'microstates';

class TodoMVC {
  todos = [Todo];
  get completed() {
    return filter(this.todos, todo => todo.state.isCompleted)
  }
}

This is great, except when it comes to creating an identity out of a microstate. There we map over each node in the microstate tree and assign an identity to it. The problem is that Filter and Union objects aren't microstates and won't be mapped. We need to make the identity mapping traverse queries like a Filter so that it can get to (and create identities for) microstates on the other side.

question How important is it for the identity for each microstate to be the same inside every point in the tree. For example, should the same instance of Todo be represented by the same identity in both the todos array and the completed array. My guess is yes.

@taras
Copy link
Member

taras commented Jul 25, 2018

How important is it for the identity for each microstate to be the same inside every point in the tree. For example, should the same instance of Todo be represented by the same identity in both the todos array and the completed array. My guess is yes.

My guess is also yes. If we can do this, then we should.

@cowboyd
Copy link
Member Author

cowboyd commented Jul 25, 2018

Ok, I think I know how to do this too. We can keep a cache of identities against Type, value pairs through the course of mapping the tree. Each time we map the identity tree, we throw away the old cache and start with a new one, so the cache will never grow beyond the values actually contained within the tree at a given time.

@taras
Copy link
Member

taras commented Jul 26, 2018

That sounds 🔥

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