Skip to content

Commit

Permalink
Merge pull request #969 from jcranendonk/remove-asap
Browse files Browse the repository at this point in the history
Remove asap package
  • Loading branch information
Jeroen Cranendonk committed Dec 12, 2019
2 parents 66984a8 + fac46c1 commit 321bca8
Show file tree
Hide file tree
Showing 14 changed files with 1,230 additions and 1,518 deletions.
1,492 changes: 686 additions & 806 deletions dist/falcor.all.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions dist/falcor.all.min.js

Large diffs are not rendered by default.

992 changes: 436 additions & 556 deletions dist/falcor.browser.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/falcor.browser.min.js

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions lib/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var ModelResponse = require("./response/ModelResponse");
var CallResponse = require("./response/CallResponse");
var InvalidateResponse = require("./response/InvalidateResponse");

var ASAPScheduler = require("./schedulers/ASAPScheduler");
var TimeoutScheduler = require("./schedulers/TimeoutScheduler");
var ImmediateScheduler = require("./schedulers/ImmediateScheduler");

Expand Down Expand Up @@ -526,19 +525,29 @@ Model.prototype._clone = function cloneModel(opts) {
/* eslint-enable */

/**
* Returns a clone of the {@link Model} that enables batching. Within the configured time period, paths for get operations are collected and sent to the {@link DataSource} in a batch. Batching can be more efficient if the {@link DataSource} access the network, potentially reducing the number of HTTP requests to the server.
* @param {?Scheduler|number} schedulerOrDelay - Either a {@link Scheduler} that determines when to send a batch to the {@link DataSource}, or the number in milliseconds to collect a batch before sending to the {@link DataSource}. If this parameter is omitted, then batch collection ends at the end of the next tick.
* Returns a clone of the {@link Model} that enables batching. Within the configured time period,
* paths for get operations are collected and sent to the {@link DataSource} in a batch. Batching
* can be more efficient if the {@link DataSource} access the network, potentially reducing the
* number of HTTP requests to the server.
*
* @param {?Scheduler|number} schedulerOrDelay - Either a {@link Scheduler} that determines when to
* send a batch to the {@link DataSource}, or the number in milliseconds to collect a batch before
* sending to the {@link DataSource}. If this parameter is omitted, then batch collection ends at
* the end of the next tick.
* @return {Model} a Model which schedules a batch of get requests to the DataSource.
*/
Model.prototype.batch = function batch(schedulerOrDelayArg) {
var schedulerOrDelay = schedulerOrDelayArg;
Model.prototype.batch = function batch(schedulerOrDelay) {
var scheduler;
if (typeof schedulerOrDelay === "number") {
schedulerOrDelay = new TimeoutScheduler(Math.round(Math.abs(schedulerOrDelay)));
scheduler = new TimeoutScheduler(Math.round(Math.abs(schedulerOrDelay)));
} else if (!schedulerOrDelay || !schedulerOrDelay.schedule) {
schedulerOrDelay = new ASAPScheduler();
scheduler = new TimeoutScheduler(1);
} else {
scheduler = schedulerOrDelay;
}

var clone = this._clone();
clone._request = new RequestQueue(clone, schedulerOrDelay);
clone._request = new RequestQueue(clone, scheduler);

return clone;
};
Expand Down
2 changes: 0 additions & 2 deletions lib/ModelRoot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var isFunction = require("./support/isFunction");
var hasOwn = require("./support/hasOwn");
var ImmediateScheduler = require("./schedulers/ImmediateScheduler");

function ModelRoot(o) {

Expand All @@ -9,7 +8,6 @@ function ModelRoot(o) {
this.syncRefCount = 0;
this.expired = options.expired || [];
this.unsafeMode = options.unsafeMode || false;
this.collectionScheduler = options.collectionScheduler || new ImmediateScheduler();
this.cache = {};

if (isFunction(options.comparator)) {
Expand Down
37 changes: 8 additions & 29 deletions lib/invalidate/invalidatePathMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ module.exports = function invalidatePathMaps(model, pathMapEnvelopes) {
var lru = modelRoot;
var expired = modelRoot.expired;
var version = incrementVersion();
var comparator = modelRoot._comparator;
var errorSelector = modelRoot._errorSelector;
var bound = model._path;
var cache = modelRoot.cache;
var node = bound.length ? getBoundValue(model, bound).value : cache;
Expand All @@ -45,10 +43,7 @@ module.exports = function invalidatePathMaps(model, pathMapEnvelopes) {

var pathMapEnvelope = pathMapEnvelopes[pathMapIndex];

invalidatePathMap(
pathMapEnvelope.json, 0, cache, parent, node,
version, expired, lru, comparator, errorSelector
);
invalidatePathMap(pathMapEnvelope.json, cache, parent, node, version, expired, lru);
}

var newVersion = cache.$_version;
Expand All @@ -59,7 +54,7 @@ module.exports = function invalidatePathMaps(model, pathMapEnvelopes) {
}
};

function invalidatePathMap(pathMap, depth, root, parent, node, version, expired, lru, comparator, errorSelector) {
function invalidatePathMap(pathMap, root, parent, node, version, expired, lru) {

if (isPrimitive(pathMap) || pathMap.$type) {
return;
Expand All @@ -69,20 +64,12 @@ function invalidatePathMap(pathMap, depth, root, parent, node, version, expired,
if (key[0] !== __prefix && hasOwn(pathMap, key)) {
var child = pathMap[key];
var branch = isObject(child) && !child.$type;
var results = invalidateNode(
root, parent, node,
key, child, branch, false,
version, expired, lru, comparator, errorSelector
);
var results = invalidateNode(root, parent, node, key, branch, expired, lru);
var nextNode = results[0];
var nextParent = results[1];
if (nextNode) {
if (branch) {
invalidatePathMap(
child, depth + 1,
root, nextParent, nextNode,
version, expired, lru, comparator, errorSelector
);
invalidatePathMap(child, root, nextParent, nextNode, version, expired, lru);
} else if (removeNodeAndDescendants(nextNode, nextParent, key, lru)) {
updateNodeAncestors(nextParent, getSize(nextNode), lru, version);
}
Expand All @@ -91,7 +78,7 @@ function invalidatePathMap(pathMap, depth, root, parent, node, version, expired,
}
}

function invalidateReference(value, root, node, version, expired, lru, comparator, errorSelector) {
function invalidateReference(root, node, expired, lru) {

if (isExpired(node)) {
expireNode(node, expired, lru);
Expand All @@ -118,11 +105,7 @@ function invalidateReference(value, root, node, version, expired, lru, comparato
do {
var key = reference[index];
var branch = index < count;
var results = invalidateNode(
root, parent, node,
key, value, branch, true,
version, expired, lru, comparator, errorSelector
);
var results = invalidateNode(root, parent, node, key, branch, expired, lru);
node = results[0];
if (isPrimitive(node)) {
return results;
Expand All @@ -138,16 +121,12 @@ function invalidateReference(value, root, node, version, expired, lru, comparato
return [node, parent];
}

function invalidateNode(
root, parent, node,
key, value, branch, reference,
version, expired, lru, comparator, errorSelector) {
function invalidateNode(root, parent, node, key, branch, expired, lru) {

var type = node.$type;

while (type === $ref) {

var results = invalidateReference(value, root, node, version, expired, lru, comparator, errorSelector);
var results = invalidateReference(root, node, expired, lru);

node = results[0];

Expand Down
27 changes: 6 additions & 21 deletions lib/invalidate/invalidatePathSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ module.exports = function invalidatePathSets(model, paths) {

var path = paths[pathIndex];

invalidatePathSet(
path, 0, cache, parent, node,
version, expired, lru
);
invalidatePathSet(path, 0, cache, parent, node, version, expired, lru);
}

// eslint-disable-next-line camelcase
Expand All @@ -68,11 +65,7 @@ function invalidatePathSet(
var key = iterateKeySet(keySet, note);

do {
var results = invalidateNode(
root, parent, node,
key, branch, false,
version, expired, lru
);
var results = invalidateNode(root, parent, node, key, branch, expired, lru);
var nextNode = results[0];
var nextParent = results[1];
if (nextNode) {
Expand All @@ -90,7 +83,7 @@ function invalidatePathSet(
} while (!note.done);
}

function invalidateReference(root, node, version, expired, lru) {
function invalidateReference(root, node, expired, lru) {

if (isExpired(node)) {
expireNode(node, expired, lru);
Expand Down Expand Up @@ -119,11 +112,7 @@ function invalidateReference(root, node, version, expired, lru) {
do {
var key = reference[index];
var branch = index < count;
var results = invalidateNode(
root, parent, node,
key, branch, true,
version, expired, lru
);
var results = invalidateNode(root, parent, node, key, branch, expired, lru);
node = results[0];
if (isPrimitive(node)) {
return results;
Expand All @@ -148,16 +137,12 @@ function invalidateReference(root, node, version, expired, lru) {
return [node, parent];
}

function invalidateNode(
root, parent, node,
key, branch, reference,
version, expired, lru) {
function invalidateNode(root, parent, node, key, branch, expired, lru) {

var type = node.$type;

while (type === $ref) {

var results = invalidateReference(root, node, version, expired, lru);
var results = invalidateReference(root, node, expired, lru);

node = results[0];

Expand Down
2 changes: 1 addition & 1 deletion lib/request/RequestQueueV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ RequestQueueV2.prototype = {
},

/**
* Removes the request from the request
* Removes the request from the request queue.
*/
removeRequest: function(request) {
var requests = this._requests;
Expand Down
21 changes: 5 additions & 16 deletions lib/schedulers/ASAPScheduler.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
var asap = require("falcor-asap");
var empty = {dispose: function() {}};
var TimeoutScheduler = require("./TimeoutScheduler");

function ASAPScheduler() {}

ASAPScheduler.prototype.schedule = function schedule(action) {
asap(action);
return empty;
};

ASAPScheduler.prototype.scheduleWithState = function scheduleWithState(state, action) {
var self = this;
asap(function() {
action(self, state);
});
return empty;
};
// Retained for backwards compatibility
function ASAPScheduler() {
return TimeoutScheduler.call(this, 1);
}

module.exports = ASAPScheduler;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"vinyl-source-stream": "^1.1.0"
},
"dependencies": {
"falcor-asap": "2.0.6",
"falcor-json-graph": "1.1.7",
"falcor-path-syntax": "0.2.4",
"falcor-path-utils": "0.7.2",
Expand Down
10 changes: 5 additions & 5 deletions test/internal/request/GetRequest.batch.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const GetRequest = require("./../../../lib/request/GetRequestV2");
const ASAPScheduler = require("./../../../lib/schedulers/ASAPScheduler");
const TimeoutScheduler = require("./../../../lib/schedulers/TimeoutScheduler");
const ImmediateScheduler = require("./../../../lib/schedulers/ImmediateScheduler");
const Model = require("./../../../lib").Model;
const LocalDataSource = require("./../../data/LocalDataSource");
Expand Down Expand Up @@ -59,7 +59,7 @@ describe("#batch", () => {

it("should make a request to the dataSource with an async scheduler.", done => {
let inlineBoolean = true;
const scheduler = new ASAPScheduler();
const scheduler = new TimeoutScheduler(1);
const getSpy = jest.fn();
const source = new LocalDataSource(Cache(), {
onGet: getSpy
Expand Down Expand Up @@ -99,7 +99,7 @@ describe("#batch", () => {
});

it("should batch some requests together.", done => {
const scheduler = new ASAPScheduler();
const scheduler = new TimeoutScheduler(1);
const getSpy = jest.fn();
const source = new LocalDataSource(Cache(), {
onGet: getSpy
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("#batch", () => {
});

it("should batch some requests together and dispose the first one.", done => {
const scheduler = new ASAPScheduler();
const scheduler = new TimeoutScheduler(1);
const getSpy = jest.fn();
const source = new LocalDataSource(Cache(), {
onGet: getSpy
Expand Down Expand Up @@ -175,7 +175,7 @@ describe("#batch", () => {
});

it("should batch some requests together and dispose the second one.", done => {
const scheduler = new ASAPScheduler();
const scheduler = new TimeoutScheduler(1);
const getSpy = jest.fn();
const source = new LocalDataSource(Cache(), {
onGet: getSpy
Expand Down
Loading

0 comments on commit 321bca8

Please sign in to comment.