Skip to content

Commit a400b99

Browse files
committed
Update 1.0.0 RFC
1 parent 743443c commit a400b99

2 files changed

Lines changed: 148 additions & 2 deletions

File tree

text/0000-refract-1.0.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ With this in mind, I'd like to start now thinking through the steps on how to pr
2323

2424
In addition to moving to 1.0.0, we need to actually start versioning namespace documents. The reason for this is that we do not want a breaking change in a namespace to require a major version bump for the entire spec.
2525

26-
**Proposal**: Start versioning current and future namespaces and move each namespace to their own repo. We can do this immediately.
26+
**Proposal**: Move all current namespaces to API Elements project.
2727

2828
## [Resolved] Namespace Functionality
2929

@@ -41,7 +41,13 @@ An important concept of Refract is that it is a model for representing data stru
4141

4242
This decoupling I think is important, because it gives freedom to implementors to implement the best way they see fit in their language/platform, and it allows for other serialization formats to spring up that may be helpful to others.
4343

44-
**Proposal**: Explain the difference in the conceptual model and the serialization formats, and potentially move these serialization descriptions to their own file in the spec repo, separating them from the main spec.
44+
**Proposal**: Explain the difference in the conceptual model and the serialization formats, and create serialization guidelines for full Refract.
45+
46+
## Inheritance
47+
48+
Inheritance can be handled differently depending on the context in which the element is found. This shows up in how we handle inheritance within the data structure elements (now in API Elements).
49+
50+
**Proposal**: Explain inheritance in some way, either in the base specification or through some type of guidelines document.
4551

4652
# Drawbacks
4753

text/0000-refract-path.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
- Start Date: 2016-01-22
2+
- RFC PR: (leave this empty)
3+
- Refract Issue: (leave this empty)
4+
5+
# Summary
6+
7+
This may scare some, but this is an RFC to propose a first iteration of Refract
8+
Path for addressing paths throughout a Refract tree.
9+
10+
# Motivation
11+
12+
When interacting with a Refract tree, it becomes cumbersome to walk down a path
13+
because of the constant need to go into the `content` property of a Refract
14+
element. It is also difficult to pass around pointers to values in a JSON
15+
representation.
16+
17+
# Detailed design
18+
19+
This design is modeled after the following:
20+
21+
- [Falcor](https://netflix.github.io/falcor/documentation/jsongraph.html)
22+
- Clojure's `get-in`
23+
- Om Next
24+
25+
The idea is the treat the Refract tree as a graph that can be queried and
26+
navigated.
27+
28+
In this design, I've also refrained as much as possible from building a query
29+
language and just using normal arrays for giving paths. I have introduced the
30+
concept of symbols, but we can easily leave them out in the first iteration.
31+
32+
The key to this design is that a path (or query if you will) requires walking
33+
down the tree and calling various data given the context in which it is found.
34+
Take this simple object as a first example.
35+
36+
```json
37+
{
38+
"foo": [
39+
{
40+
"bar": "baz"
41+
}
42+
]
43+
}
44+
```
45+
46+
Since we know that an object with an `element` property is a Refract element,
47+
we can treat our objects accordingly. This means if I want the value `baz`
48+
above, we can use a path like this, represented as a JSON array.
49+
50+
```json
51+
["foo", 1, "bar"]
52+
```
53+
54+
There are a few things we would assume here:
55+
56+
1. When in a normal object, a string is a reference to a property of that
57+
object (like with `"foo"`).
58+
2. When in a normal array, an integer gets the item at the given index.
59+
60+
Now as we look at using this for Refract objects, we handle the path a little
61+
differently.
62+
63+
```json
64+
{
65+
"element": "object",
66+
"content": [
67+
{
68+
"element": "member",
69+
"content": {
70+
"key": {
71+
"element": "string",
72+
"content": "foo"
73+
},
74+
"value": {
75+
"element": "array",
76+
"content": [
77+
{
78+
"element": "object",
79+
"content": [
80+
{
81+
"element": "member",
82+
"content": {
83+
"key": {
84+
"element": "string",
85+
"content": "bar"
86+
},
87+
"value": {
88+
"element": "string",
89+
"content": "baz"
90+
}
91+
}
92+
}
93+
]
94+
}
95+
]
96+
}
97+
}
98+
}
99+
]
100+
}
101+
```
102+
103+
To get the value of `bar`, you would use a very similar path. The path
104+
`["foo", 1, "bar", ':value']` would return the same value as the one above. What
105+
`:value` does is ensure that you always get the content of the final path item,
106+
whether it's an element or whether it's a normal value. There are few rules for
107+
this here.
108+
109+
1. If an element with a content that is an array, and a number is given, it
110+
returns the corresponding index in `content`.
111+
2. If an element is the current path, and a string is given, it returns the
112+
value of where the content of the `key` matches.
113+
3. The `:value` symbol returns either the `content` of an element or the actual
114+
value itself of the element. This is for situations where a value can either
115+
be refracted or a primitive JSON value.
116+
117+
We can use similar special symbols for getting the value of element, meta, or
118+
attributes.
119+
120+
```json
121+
["foo", ":meta", "title", ":value"]
122+
```
123+
124+
This path will return the value of `title`, whether it's refracted or not.
125+
126+
In light of this, implementation SHOULD treat paths that did not return value to
127+
be some form of a "not found" value. It's up the implementation to decide how
128+
to interpret this kind of query result.
129+
130+
# Drawbacks
131+
132+
Why should we *not* do this?
133+
134+
# Alternatives
135+
136+
What other designs have been considered? What is the impact of not doing this?
137+
138+
# Unresolved questions
139+
140+
What parts of the design are still TBD?

0 commit comments

Comments
 (0)