Skip to content

Commit

Permalink
Some jsdoc fixes and implemented "blocks.debug.pause()" and
Browse files Browse the repository at this point in the history
"blocks.debug.resume()" and used it at some methods.
This is mostly a fix for observables because blocks.debug.chackArgs unwraps observables that
aren't ready (e.g. in initialisation or when there context get bound to a
view).
  • Loading branch information
Joscha Rohmann committed Aug 20, 2016
1 parent 0345b25 commit 6667249
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
35 changes: 17 additions & 18 deletions lib/blocks/jsdebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ blocks.debug = {
disable: function () {
blocks.debug.enabled = false;
},

pause: function () {
blocks.debug.paused++;
},
resume: function () {
blocks.debug.paused--;
},
addType: function (name, checkCallback) {
customTypes[name.toLowerCase()] = checkCallback;
},

paused: 0,
checkArgs: debugFunc(function (method, args, options) {
if (!blocks.debug.enabled) {
return;
Expand Down Expand Up @@ -74,8 +79,8 @@ blocks.debug = {
message.print();
},

checkQuery: function (name, args, query, element) {
if (!blocks.debug.enabled || name == 'if' || name == 'ifnot') {
checkQuery: debugFunc(function (name, args, query, element) {
if (name == 'if' || name == 'ifnot') {
return;
}
var method = blocks.debug.queries[name];
Expand All @@ -85,12 +90,9 @@ blocks.debug = {
element: element
});
}
},
}),

queryNotExists: function (query, element) {
if (!blocks.debug.enabled) {
return;
}
queryNotExists: debugFunc(function (query, element) {
var message = blocks.debug.Message();
message.beginSpan({ 'font-weight': 'bold' });
message.addSpan('Warning:', { background: 'orange', padding: '0 3px' });
Expand All @@ -106,12 +108,9 @@ blocks.debug = {
message.endSpan();

message.print();
},
}),

queryParameterFail: function (query, failedParameter, element) {
if (!blocks.debug.enabled) {
return;
}
queryParameterFail: debugFunc(function (query, failedParameter, element) {
var method = blocks.debug.queries[query.name];
var message = blocks.debug.Message();
var params = query.params;
Expand Down Expand Up @@ -146,9 +145,9 @@ blocks.debug = {
message.endGroup();

message.print();
},
}),

expressionFail: function (expressionText, element) {
expressionFail: debugFunc(function (expressionText, element) {
if (!blocks.debug.enabled) {
return;
}
Expand All @@ -164,7 +163,7 @@ blocks.debug = {
tryInsertElement(message, element);

message.print();
},
}),

Message: ConsoleMessage
};
Expand Down Expand Up @@ -320,7 +319,7 @@ function addError(message, error, method, paramNames) {

function debugFunc(callback) {
return function () {
if (blocks.debug.executing||!blocks.debug.enabled) {
if (blocks.debug.executing || !blocks.debug.enabled || blocks.debug.paused > 0) {
return;
}
blocks.debug.executing = true;
Expand Down
1 change: 1 addition & 0 deletions src/mvc/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ define([
* @memberof Collection
* @param {Object} [params] - The parameters Object that will be used to populate the
* Collection from the specified options.read URL. If the URL does not contain parameters
* @param {Function} [callback] - A callback function that will be called when the data is available.
* @returns {Collection} - Chainable. Returns the Collection itself - return this;
*
* @example {javascript}
Expand Down
3 changes: 2 additions & 1 deletion src/mvc/bindContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define([
function bindContext (context, object) {
var key;
var value;

/* @if DEBUG */ blocks.debug.pause(); /* @endif */
if (!object) {
object = context;
}
Expand All @@ -19,6 +19,7 @@ define([
}

}
/* @if DEBUG */ blocks.debug.resume(); /* @endif */
}
return bindContext;
});
6 changes: 3 additions & 3 deletions src/query/ElementsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var ElementsData = (function () {
var data = {};
var globalId = 1;

function getDataId(element) {
var result = element ? VirtualElement.Is(element) ? element._state ? element._state.attributes[dataIdAttr] : element._attributes[dataIdAttr] :
element.nodeType == 1 ? element.getAttribute(dataIdAttr) :
Expand Down Expand Up @@ -49,7 +49,7 @@
var isVirtual = element && element.__identity__ == virtualElementIdentity;
var currentData;
var id;

if (isVirtual) {
currentData = data[element._getAttr(dataIdAttr)];
} else {
Expand Down Expand Up @@ -133,7 +133,7 @@
});
data[id] = undefined;
if (VirtualElement.Is(element)) {
element.attr(dataIdAttr, null);
element.removeAttr(dataIdAttr);
} else if (element.nodeType == 1) {
element.removeAttribute(dataIdAttr);
}
Expand Down
6 changes: 4 additions & 2 deletions src/query/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ define([
};

initialValue = blocks.unwrap(initialValue);
/* @if DEBUG */ blocks.debug.executing = true; /* @endif */
/* @if DEBUG */ blocks.debug.pause(); /* @endif */
blocks.extend(observable, blocks.observable.fn.base);
/* @if DEBUG */ blocks.debug.executing = false; /* @endif */
/* @if DEBUG */ blocks.debug.resume(); /* @endif */
observable.__id__ = observableId++;
observable.__value__ = initialValue;
observable.__context__ = thisArg || blocks.__viewInInitialize__ || observable;
Expand Down Expand Up @@ -87,7 +87,9 @@ define([

function updateDependencies(observable) {
if (observable._dependencyType) {
/* @if DEBUG */ blocks.debug.pause(); /* @endif */
observable._getDependency = blocks.bind(getDependency, observable);
/* @if DEBUG */ blocks.debug.resume(); /* @endif */
observable.on('get', observable._getDependency);
}
}
Expand Down

0 comments on commit 6667249

Please sign in to comment.