Skip to content

Returning empty object when getting branch nodes (useful for decoupling deref) #951

@augonis

Description

@augonis

An example to illustrate.

var model = new falcor.Model({
  cache: {
    todos: {
      a:{
        name: 'get milk from corner store',
        done: false
      },
    }
  }});

model.get('todos.a').then(j => console.log(JSON.stringify(j, null, 2)))

//prints
{
  "json": {
    "todos": {
      "$__path": ["todos"]
    }
  }
}

There's no mention of the path I asked for (implying it doesn't exist?)
Instead I propose to make the response be

{
  "json": {
    "todos": {
      "$__path": ["todos"]
      "a": {
        "$__path": ["todos", "a"]
      }
    }
  }
}

It includes the requested path, indicating that there is something beyond there and giving its optimized path ripe for model.deref(). This is in line with Falcors philosophy of only returning what the client asked for.

This change would be most useful for a controller handing out dereferenced models to views.
One can imagine a generic list view that (itself been given a model dereferenced to an array) creating child views with models dereferenced to individual array items.
Currently it is impossible to dereference any item without knowledge of some leaf value within (or beyond) the item, preventing the creation of such truly generic list view.

I don't see this change would break something, but I might be wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions