var classify = require('protean/function/classify'); var atoms = require('protean/falcor/graph/atoms'); /** * A Falcor DataSource that proxies another data source and sets all returned * atoms to expire immediately. * * **file:** [falcor/data-source/no-cache.js](falcor/data-source/no-cache.js) * * @class NoCacheSource * @extends ProteanClass * @implements DataSource * @param {Object} opts * @param {DataSource} opts.source */ function NoCacheSource (opts) { opts = opts || {}; this.source = opts.source; } module.exports = classify(NoCacheSource,/** @lends NoCacheSource# */{ /** * @param {PathSets[]} paths * @returns {Observable} */ get: function (paths) { return this.source.get(paths).select(this._expire); }, /** * @param {JSONGraphEnvelope} envelope * @returns {Observable} */ set: function (envelope) { return this.source.set(envelope).select(this._expire); }, /** * @param {PathSet} path * @param {Array} args * @param {PathSet[]} refSuffixes * @param {PathSet[]} thisPaths * @returns {Observable} */ call: function (path, args, refSuffixes, thisPaths) { return this. source. call(path, args, refSuffixes, thisPaths). select(this._expire); }, /** * @private * @param {JSONGraphEnvelope} envelope * @returns {JSONGraphEnvelope} */ _expire: function (envelope) { if (envelope.jsonGraph) { atoms(envelope.jsonGraph, function (path, atom) { atom.$expires = 0; }); } return envelope; } });