Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making it possible to order observation updates by their depth automatically #155

Merged
merged 5 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions can-observation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var getValueDependenciesSymbol = canSymbol.for("can.getValueDependencies");

// ## Observation constructor
function Observation(func, context, options){
this.deriveQueue = queues.deriveQueue;

this.func = func;
this.context = context;
this.options = options || {priority: 0, isObservable: true};
Expand Down Expand Up @@ -99,7 +101,8 @@ canReflect.assign(Observation.prototype, {
this,
[],
{
priority: this.options.priority
priority: this.options.priority,
element: this.options.element
}
];
//!steal-remove-start
Expand All @@ -109,7 +112,8 @@ canReflect.assign(Observation.prototype, {
this,
[],
{
priority: this.options.priority
priority: this.options.priority,
element: this.options.element
/* jshint laxcomma: true */
, log: [ canReflect.getName(this.update) ]
/* jshint laxcomma: false */
Expand All @@ -121,7 +125,7 @@ canReflect.assign(Observation.prototype, {
}
//!steal-remove-end
// Update this observation after all `notify` tasks have been run.
queues.deriveQueue.enqueue.apply(queues.deriveQueue, queuesArgs);
this.deriveQueue.enqueue.apply(this.deriveQueue, queuesArgs);
}
},
// Called to update its value as part of the `derive` queue.
Expand Down Expand Up @@ -168,7 +172,7 @@ canReflect.assign(Observation.prototype, {
// It's possible that a child dependency of this observable might be queued
// to change. Check all child dependencies and make sure they are up-to-date by
// possibly running what they have registered in the derive queue.
if(queues.deriveQueue.tasksRemainingCount() > 0) {
if(this.deriveQueue.tasksRemainingCount() > 0) {
Observation.updateChildrenAndSelf(this);
}

Expand Down Expand Up @@ -239,6 +243,10 @@ var observationProto = {
},
"can.setPriority": function(priority){
this.options.priority = priority;
},
"can.setElement": function(element) {
this.options.element = element;
this.deriveQueue = queues.domQueue || queues.deriveQueue;
}
};

Expand All @@ -261,10 +269,10 @@ Observation.updateChildrenAndSelf = function(observation){
// the value is right.
// > NOTE: This only works for `Observation` right now. We need a way of knowing how
// > to find what an observable might have in the `deriveQueue`.
if(observation.update !== undefined && queues.deriveQueue.isEnqueued( observation.update ) === true) {
if(observation.update !== undefined && observation.deriveQueue.isEnqueued( observation.update ) === true) {
// TODO: In the future, we should be able to send log information
// to explain why this needed to be updated.
queues.deriveQueue.flushQueuedTask(observation.update);
observation.deriveQueue.flushQueuedTask(observation.update);
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@
"can-log": "^1.0.0",
"can-namespace": "1.0.0",
"can-observation-recorder": "^1.0.0",
"can-queues": "^1.0.0",
"can-queues": "^1.3.0",
"can-reflect": "^1.7.0",
"can-symbol": "^1.4.2"
},
"devDependencies": {
"bit-docs": "^0.0.7",
"can-cid": "^1.0.0",
"detect-cyclic-packages": "^1.1.0",
"docco": "^0.7.0",
Expand Down