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

RFC: @computed directive #116

Open
mattkrick opened this issue Sep 9, 2016 · 0 comments
Open

RFC: @computed directive #116

mattkrick opened this issue Sep 9, 2016 · 0 comments

Comments

@mattkrick
Copy link
Owner

let's say you have a bunch of agenda items

  1. mow the lawn
  2. eat
  3. ???
  4. profit

The URL looks like this /agenda/2
Since we're on page 2, that means 1 must be completed, so it should have a strikethrough.
That also means "eat" should be BOLD, since that's active.

This is an example of merging local state with domain state.
I have a goal to declaratively put house all data requirements inside a GraphQL query

to do this one, the query might look like this:

agenda(teamId: $teamId) @live {
    id
    content
    isComplete
    sortOrder
    teamMemberId
    status @computed
}

The problem is that GraphQL doesn't provide the index to each child. We could do it internally & give it something like source.__idx.

Relying on index is fascinating because the sort/filter doesn't happen until after the index, which means we'd have to denormalize the values, perform a sort/filter, then go back & fill in the computed values.

This is actually pretty easy. When resolving a scalar, see if it's computed. If so, don't write a value yet. Instead, push a function that will write a value to the field to an computedValQueue. Then, after sort/filter, run through the computedValueQueue stack. We'll only run this once, in case people get cute & try to sort on a computed value.

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