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

Support MSON inheritance #26

Open
danielgtaylor opened this issue May 20, 2015 · 7 comments
Open

Support MSON inheritance #26

danielgtaylor opened this issue May 20, 2015 · 7 comments
Assignees

Comments

@danielgtaylor
Copy link
Contributor

Right now this won't behave as expected. Think of the MSON which defines one type which is an object, then another which inherits from it:

  • A (object)
  • B (A)
    • C: test

Without expansion/preprocessing it's likely it will get expanded to something like this:

['object', {name: 'Data types'}, {}, [
  ['object', {name: 'A'}, {}, []],
  ['A', {name: 'B'}, {}, [
    ['string', {name: 'C'}, {}, 'test']
  ]]
]

In the above example we'll get an ElementType for B instead of ObjectType because there is no registered type for A. That means that B.content will be the raw content above instead of proper element instances. The solution may be to create some kind of lookup tree for the base type or some kind of preprocessing loop. Ideas?

@zdne
Copy link
Member

zdne commented May 21, 2015

I think refract implementations should provide this lookup – expansion – at least we are going to implement it in the C++ counterpart (cc @klokane)

@smizell
Copy link
Contributor

smizell commented May 21, 2015

@zdne @danielgtaylor This is something we need to decide. How does an MSON structure get converted into a normal Refract structure? I don't think Minim should handle that explicitly, though I think we can make some things that derive element definitions from a structure (which is essentially what MSON does).

First, let me change up the example above to match the MSON.

MSON:

  • A (object)
  • B (A)
    • C: test

Refract

["object", { "title": "Data types" }, {}, [
  ["object", { "id": "A", "name": "A" }, {}, {}],
  ["A", { "id": "B", "name": "B" }, {}, [
    ["string", { "name": "C" }, {}, "test"]
  ]]
]]

At this point, this is all Refract should do. MSON structures have their own way of representing the data. If you ran through something to convert to use MSON inheritance there are several steps we could take. First, convert

["object", { "title": "Data types" }, {}, [
  ["object", { "id": "A", "name": "A" }, {}, {}],
  ["extend", { "id": "B", "name": "B" }, {}, [
    ["ref", {}, {}, "A"],
    ["object", {}, {}, [
      ["string", { "name": "C" }, {}, "test"]
    ]]
  ]]
]]

Then dereference the A reference.

["object", { "title": "Data types" }, {}, [
  ["object", { "id": "A", "name": "A" }, {}, {}],
  ["extend", { "id": "B", "name": "B" }, {}, [
    ["object", { "ref": "A" }, {}, {}],
    ["object", {}, {}, [
      ["string", { "name": "C" }, {}, "test"]
    ]]
  ]]
]]

Finally compute extend:

["object", { "title": "Data types" }, {}, [
  ["object", { "id": "A", "name": "A" }, {}, {}],
  ["object", { "id": "B", "name": "B", "ref": "A" }, {}, [
    ["string", { "name": "C" }, {}, "test"]
  ]]
]]

Is this correct? Thoughts? I think we can make the jump straight to the end, but wanted to show some intermediate steps.

@smizell
Copy link
Contributor

smizell commented May 21, 2015

The solution may be to create some kind of lookup tree for the base type or some kind of preprocessing loop. Ideas?

I'm not sure the best way to do this. I'd be interested to see what the C++ say above doing this. I'm wondering if we will have to make two passes on the document.

@klokane
Copy link
Contributor

klokane commented May 22, 2015

I still have no completed expansion. But way how i will to complete it

  • parse all without any expansion
  • create registry, walk throught elements (into deep of any leaf), registrate all ID and map them to element
  • expansion - walk throught element tree again and recursive expansion of any element

How I understand to refract, expansion should provide complete resolution of every any type up to primitives w/o any linking.

I hope we will discuss it today with @zdne

@smizell
Copy link
Contributor

smizell commented May 22, 2015

I still have no completed expansion. But way how i will to complete it

I like it. Seems correct.

How I understand to refract, expansion should provide complete resolution of every any type up to primitives w/o any linking.

I think you're correct, but there are some cases around this to discuss. For example, Refract inheritance by default is simply inheriting the definition of the element, but does not inherit the actual data. In MSON, though, elements will actually inherit data from their respective parents. I think we need to discuss how to convey this, because I think by default Refract will act differently than MSON.

Hope that makes sense.

@klokane
Copy link
Contributor

klokane commented May 22, 2015

Refract inheritance by default is simply inheriting the definition of the element, but does not inherit the actual data.

Good to know, I miss it :)

@kylef kylef self-assigned this Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants