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

Trees of varying depths #6

Open
justinbmeyer opened this issue Oct 31, 2017 · 0 comments
Open

Trees of varying depths #6

justinbmeyer opened this issue Oct 31, 2017 · 0 comments

Comments

@justinbmeyer
Copy link
Contributor

I'm not sure can-key-tree should take this on, but it would be helpful in some places for KeyTree to support in some way trees of varying depths. This issue explores one idea.

Lets say I had a structure similar to the DependencyRecord type in can-observation-recorder:

var dependencyRecord = {
  keyDependencies: Map{
    [person]: Set["first", "last"]
  },
  valueDependencies: Set[ageCompute]
}

I would like to easily be able to add and remove values to this tree, especially the keyDependencies Map with the familiar tree.add() api:

dependencyRecord.add(["keyDependencies", person, "first"])
dependencyRecord.add(["valueDependencies", ageCompute])

One way might be to support creating a tree of trees, where the nodes can be determined by their parent key:

dependencyRecord = new KeyTree([{
  keyDependencies: KeyTree.extend([Map, Set]),
  valueDependencies: KeyTree.extend([Map, Set])
}])

Then:

dependencyRecord.add(["keyDependencies", [person, "first"] ]);
dependencyRecord.add(["valueDependencies", [ageCompute] ]);

For something like https://github.com/canjs/can-reflect-mutate-dependencies

mutateStore = new KeyTree([ WeakMap, {
  mutateDependenciesForKey: KeyTree.extend([ Map, DependencyRecord ])
  mutateDependenciesForValue: DependencyRecord
}])
// john.on("born", function(){ fred.age = 0; })

mutateStore.add(
  [ fred, "mutateDependenciesForKey",
    [ "age", 
      ["keyDependencies", 
        [john, "born"]
      ]
    ]
  ])
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

1 participant