Closed Bug 760184 Opened 12 years ago Closed 9 years ago

[Architecture] Convert complex JSON structures into proper deep models/collections

Categories

(Pancake Graveyard :: Front-end, enhancement)

x86
macOS
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: gbrander, Unassigned)

References

()

Details

(Keywords: arch)

We've been using a memoized collection pattern for deep models and collections. For example:

    StackModel
      eras() -> EraCollection
        EraModel
          places() -> PlaceCollection
            SiteModel

I've created a standard way to generate these memoized sub-collections, complete with event republishing (BaseModel.subcollection). However, there is no easy way to build these structures with nested JSON, making the parse method less useful and fairly confusing to implement.

A couple possible approaches:

* Use a 3rd Party Backbone deep-modeling library
* Create some sort of parse method for add() that can tease apart deep JSON and populate sub-collections/models.
Some promising deep modeling libraries for Backbone:

https://github.com/PaulUithol/Backbone-relational
https://github.com/powmedia/backbone-deep-model

I'm leaning away from the relational model, since it's more SQL-style then JSON-style.
Our sub-collection approach has been OK for one level of relatedness, but breaks down with more. You end up with race conditions, where a child model may not have access to parent collections/models, because they haven't been added to a collection yet.
There's support for schema and custom object => constructor mapping in the json/ref module which I'm looking into for a side-project. That would let us load JSON normally, and do json.resolveJson( resp, { schemas: [ ... ] } ). I'm tracking down exactly what that schemas property contains, how the mapping is constructed (and if it ends up being useful.) json/ref also supports the notion of loaders and lazy-loading of property values that might be useful here.
For now, I need to represent vanilla hierarchical JSON data structures as models/collections. I also need the conversion to be easy to implement in `parse`.

Currently, we need:

* Nested models/collections
* (Maybe) deep property access
* Event republishing for nested structures. We probably should republish under a channel name that reflects the structure. E.g., binding to a child model's change event from a parent might look like `bind('change:eras.era.places.place.title')`.
* A way to access an object's parent (if we have multiple parents, this may be better expressed in terms of relationships, but that hasn't happened yet).

I'm OK with holding off on circular refs, lazy loading, buffers until we have a need for them, but if we get them for free, that's cool too.
To be clear, this is a blocker for doing any kind of session, or server-side management of "Eras" in the accordion drawer: https://bugzilla.mozilla.org/show_bug.cgi?id=758019.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.