Skip to main content

ModelResponse

new ModelResponse()

A ModelResponse is a container for the results of a get, set, or call operation performed on a Model. The ModelResponse provides methods which can be used to specify the output format of the data retrieved from a Model, as well as how that data is delivered.

Source:
response/ModelResponse.js, line 5

Extends

Methods

forEach(onNextnullable, onErrornullable, onCompletednullable) → {Subscription}

The forEach method is a synonym for Observable.prototype.subscribe and triggers the execution of the Observable, causing the values within to be pushed to a callback. An Observable is like a pipe of water that is closed. When forEach is called, we open the valve and the values within are pushed at us. These values can be received using either callbacks or an Observer object.

Parameters:
Name & Attributes Type Description
onNext
nullable
Observable~onNextCallback

a callback that accepts the next value in the stream of values

onError
nullable
Observable~onErrorCallback

a callback that accepts an error that occurred while evaluating the operation underlying the Observable stream

onCompleted
nullable
Observable~onCompletedCallback

a callback that is invoked when the Observable stream has ended, and the Observable~onNextCallback will not receive any more values

Overrides:
Observable#forEach
Source:
typedefs/Observable.js, line 6
Return Type:
Subscription

progressively() → {ModelResponse.<JSONEnvelope>}

The progressively method breaks the response up into two parts: the data immediately available in the Model cache, and the data in the Model cache after the missing data has been retrieved from the DataSource. The progressively method creates a ModelResponse that immediately returns the requested data that is available in the Model cache. If any requested paths are not available in the cache, the ModelResponse will send another JSON message with all of the requested data after it has been retrieved from the DataSource.

Source:
response/ModelResponse.js, line 22
Returns:

the values found at the requested paths.

Return Type:
ModelResponse.<JSONEnvelope>
Example
var dataSource = (new falcor.Model({
  cache: {
    user: {
      name: "Steve",
      surname: "McGuire",
      age: 31
    }
  }
})).asDataSource();

var model = new falcor.Model({
  source: dataSource,
  cache: {
    user: {
      name: "Steve",
      surname: "McGuire"
    }
  }
});

model.
  get(["user",["name", "surname", "age"]]).
  progressively().
  // this callback will be invoked twice, once with the data in the
  // Model cache, and again with the additional data retrieved from the DataSource.
  subscribe(function(json){
    console.log(JSON.stringify(json,null,4));
  });

// prints...
// {
//     "json": {
//         "user": {
//             "name": "Steve",
//             "surname": "McGuire"
//         }
//     }
// }
// ...and then prints...
// {
//     "json": {
//         "user": {
//             "name": "Steve",
//             "surname": "McGuire",
//             "age": 31
//         }
//     }
// }

subscribe(onNextnullable, onErrornullable, onCompletednullable) → {Subscription}

The subscribe method is a synonym for Observable.prototype.forEach and triggers the execution of the Observable, causing the values within to be pushed to a callback. An Observable is like a pipe of water that is closed. When forEach is called, we open the valve and the values within are pushed at us. These values can be received using either callbacks or an Observer object.

Parameters:
Name & Attributes Type Description
onNext
nullable
Observable~onNextCallback

a callback that accepts the next value in the stream of values

onError
nullable
Observable~onErrorCallback

a callback that accepts an error that occurred while evaluating the operation underlying the Observable stream

onCompleted
nullable
Observable~onCompletedCallback

a callback that is invoked when the Observable stream has ended, and the Observable~onNextCallback will not receive any more values

Overrides:
Observable#subscribe
Source:
typedefs/Observable.js, line 17
Return Type:
Subscription