From 4523e2105dd1a390bb2125f48f20eb9ff241a337 Mon Sep 17 00:00:00 2001 From: Jafar Husain Date: Sat, 8 Aug 2015 20:20:54 -0700 Subject: [PATCH] Update ModelResponse.js --- lib/response/ModelResponse.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/response/ModelResponse.js b/lib/response/ModelResponse.js index bcf5a9e2..63ff040b 100644 --- a/lib/response/ModelResponse.js +++ b/lib/response/ModelResponse.js @@ -41,6 +41,34 @@ ModelResponse.prototype.mixin = function mixin() { }); }; +/** + * Converts the data format of the data in a JSONGraph Model response to a stream of path values. + * @name toPathValues + * @memberof ModelResponse.prototype + * @function + * @return ModelResponse. + * @example +var model = new falcor.Model({ + cache: { + user: { + name: "Steve", + surname: "McGuire" + } + } +}); + +model. + get(["user",["name", "surname"]]). + toPathValues(). + // this method will be called twice, once with the result of ["user", "name"] + // and once with the result of ["user", "surname"] + subscribe(function(pathValue){ + console.log(JSON.stringify(pathValue)); + }); +// prints... +"{\"path\":[\"user\",\"name\"],\"value\":\"Steve\"}" +"{\"path\":[\"user\",\"surname\"],\"value\":\"McGuire\"}" + */ ModelResponse.prototype.toPathValues = function toPathValues() { return this.mixin(valuesMixin).asObservable(); };