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

Add asJSON and asJSONGraph mode to Model #131

Closed
jhusain opened this issue Apr 22, 2015 · 1 comment
Closed

Add asJSON and asJSONGraph mode to Model #131

jhusain opened this issue Apr 22, 2015 · 1 comment
Assignees

Comments

@jhusain
Copy link
Contributor

jhusain commented Apr 22, 2015

Iintroduce two Model modes: asJSON and asJSONGraph. The Model's default mode will be graph. These modes would create new Models, not mutate the existing one.

model.asTree().get("profiles[0..5].name")

In tree mode, all references are followed even if they are in found in the last key of the path. Sets behave the same way they would against a JSON object, replacing the target of a reference instead of the reference itself. This means that in tree mode the model will always emit JSON. In graph mode you can select references with paths, or select their target with a trailing null in the path. The null key will be aliased to a constant (REF_TARGET) for more readability. Note that null will only be necessary in the rare case in which references point to values.

This proposal can be clearly explained to developers using the same narrative we use to justify the JSON Graph language: JSON can't have refs. If you want to use a Graph, you go into Graph mode. If you want a tree, you will never see references.

Now that tree and graph moods are available, the model response output format options can be to just PathValue or Value. We've effectively separated the output format dimension from the behavior of whether the Model behaves like a tree or graph, which is a nice simplification.

@ThePrimeagen
Copy link
Contributor

@jhusain Is this a functional completeness task? If so the router stuff must stop for me to complete this.

@trxcllnt trxcllnt closed this as completed May 6, 2015
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

3 participants