-
Notifications
You must be signed in to change notification settings - Fork 53
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
Abstract relationships. #358
Conversation
9a74458
to
e335caf
Compare
One thing I was thinking was that instead of using class Edge {
get targetValue() {
return view(At(this.name), this.parentValue);
}
get parentValue() {
return valueOf(this.parent);
}
constructor(parent, key) {
this.parent = parent;
this.name = name;
}
} And then the relationship traversal would receive an type Traversal = (edge: Edge) => Cell |
1d3908f
to
74a5def
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should release this as a beta and test out in all of the use cases that we have.
Here is a branch using an |
Edge looks like the way to go because it gives us a richer object to use in the future. Should I create a beta release from edge? |
74a5def
to
f1c1d37
Compare
@taras This PR now uses the |
Here is a TypeScript definition for relationships https://gist.github.com/cowboyd/5fd38eb194fc362457909d9dd762f15e |
7fd81fa
to
0d8c44e
Compare
How to contextualize a child microstate has been a constant challenge. In other words, sometimes you want a child to take on a constant value. Sometimes you want it to take on a default value, and sometime you might want it to be completly polymorphic on what value it takes on depending on the parent. Unfortunately, this is not possible with our current way of expressing relationships with is either with a DSL: ```js class Counter { count = Number; } ``` or with an explicitly created microstate: ```js class Counter { count = create(Number, 1); } ``` The problem is that there is no way to expand the concept of what gets created if you want to do something fancier, like copy values down the graph without resorting to intializer hacks. This introduces a very thin concept of a _relationship_ between a parent microstate and a child microstate. The responsibility of the traversal is to take the value at the location of the target microstate and return a specifier for the child microstate. To do this, we introduce the concept of a "Cell" which is a Type, value pair `{ Type, value }`. This is the minimal about of information required to specify a microstate. This is super light-weight because it does not require the overhead of actually `create`-ing a microstate. It is the responsibility of a relationship to resolve a value into a cell. > Note: in future microstates, we will use `{ Type, path }` as a cell specifier. The relationship class is organized monadically so that it can be mapped, flatMapped, etc... and any relationship can be extended using `map` and `flatMap` For example, to implement a hypothetical `child` helper which creates a specifies a substate of a given type and default value, it could look like this. ```js function child(Type, defaultValue) { return relationship() .map(({ value }) => value != null ? {Type, value} : {Type, value: defaultValue }) } ```
0d8c44e
to
aabfdf3
Compare
This PR is available to use: npm install [email protected]
You can view the NPM package here. |
See #357 for full details.
How to contextualize a child microstate has been a constant challenge. In other words, sometimes you want a child to take on a constant value. Sometimes you want it to take on a default value, and sometime you might want it to be completly polymorphic on what value it takes on depending on the parent.
Unfortunately, this is not possible with our current way of expressing relationships with is either with a DSL:
or with an explicitly created microstate:
The problem is that there is no way to expand the concept of what gets created if you want to do something fancier, like copy values down the graph without resorting to intializer hacks.
This introduces a very thin concept of a relationship between a parent microstate and a child microstate. The responsibility of the traversal is to take the value at the location of the target microstate and return a specifier for the child microstate.
To do this, we introduce the concept of a "Cell" which is a Type, value pair
{ Type, value }
. This is the minimal about of information required to specify a microstate. This is super light-weight because it does not require the overhead of actuallycreate
-ing a microstate.It is the responsibility of a relationship to resolve a value into a cell.
The relationship class is organized monadically so that it can be mapped, flatMapped, etc... and any relationship can be extended using
map
andflatMap
For example, to implement a hypothetical
child
helper which creates a specifies a substate of a given type and default value, it could look like this.This pull request does not introduce any actual changes built on the
relationship
function, but just exposes it so that we can experiment with it.