Skip to content

Commit 6667249

Browse files
author
Joscha Rohmann
committed
Some jsdoc fixes and implemented "blocks.debug.pause()" and
"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).
1 parent 0345b25 commit 6667249

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

lib/blocks/jsdebug.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ blocks.debug = {
1111
disable: function () {
1212
blocks.debug.enabled = false;
1313
},
14-
14+
pause: function () {
15+
blocks.debug.paused++;
16+
},
17+
resume: function () {
18+
blocks.debug.paused--;
19+
},
1520
addType: function (name, checkCallback) {
1621
customTypes[name.toLowerCase()] = checkCallback;
1722
},
18-
23+
paused: 0,
1924
checkArgs: debugFunc(function (method, args, options) {
2025
if (!blocks.debug.enabled) {
2126
return;
@@ -74,8 +79,8 @@ blocks.debug = {
7479
message.print();
7580
},
7681

77-
checkQuery: function (name, args, query, element) {
78-
if (!blocks.debug.enabled || name == 'if' || name == 'ifnot') {
82+
checkQuery: debugFunc(function (name, args, query, element) {
83+
if (name == 'if' || name == 'ifnot') {
7984
return;
8085
}
8186
var method = blocks.debug.queries[name];
@@ -85,12 +90,9 @@ blocks.debug = {
8590
element: element
8691
});
8792
}
88-
},
93+
}),
8994

90-
queryNotExists: function (query, element) {
91-
if (!blocks.debug.enabled) {
92-
return;
93-
}
95+
queryNotExists: debugFunc(function (query, element) {
9496
var message = blocks.debug.Message();
9597
message.beginSpan({ 'font-weight': 'bold' });
9698
message.addSpan('Warning:', { background: 'orange', padding: '0 3px' });
@@ -106,12 +108,9 @@ blocks.debug = {
106108
message.endSpan();
107109

108110
message.print();
109-
},
111+
}),
110112

111-
queryParameterFail: function (query, failedParameter, element) {
112-
if (!blocks.debug.enabled) {
113-
return;
114-
}
113+
queryParameterFail: debugFunc(function (query, failedParameter, element) {
115114
var method = blocks.debug.queries[query.name];
116115
var message = blocks.debug.Message();
117116
var params = query.params;
@@ -146,9 +145,9 @@ blocks.debug = {
146145
message.endGroup();
147146

148147
message.print();
149-
},
148+
}),
150149

151-
expressionFail: function (expressionText, element) {
150+
expressionFail: debugFunc(function (expressionText, element) {
152151
if (!blocks.debug.enabled) {
153152
return;
154153
}
@@ -164,7 +163,7 @@ blocks.debug = {
164163
tryInsertElement(message, element);
165164

166165
message.print();
167-
},
166+
}),
168167

169168
Message: ConsoleMessage
170169
};
@@ -320,7 +319,7 @@ function addError(message, error, method, paramNames) {
320319

321320
function debugFunc(callback) {
322321
return function () {
323-
if (blocks.debug.executing||!blocks.debug.enabled) {
322+
if (blocks.debug.executing || !blocks.debug.enabled || blocks.debug.paused > 0) {
324323
return;
325324
}
326325
blocks.debug.executing = true;

src/mvc/Collection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ define([
7373
* @memberof Collection
7474
* @param {Object} [params] - The parameters Object that will be used to populate the
7575
* Collection from the specified options.read URL. If the URL does not contain parameters
76+
* @param {Function} [callback] - A callback function that will be called when the data is available.
7677
* @returns {Collection} - Chainable. Returns the Collection itself - return this;
7778
*
7879
* @example {javascript}

src/mvc/bindContext.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ define([
44
function bindContext (context, object) {
55
var key;
66
var value;
7-
7+
/* @if DEBUG */ blocks.debug.pause(); /* @endif */
88
if (!object) {
99
object = context;
1010
}
@@ -19,6 +19,7 @@ define([
1919
}
2020

2121
}
22+
/* @if DEBUG */ blocks.debug.resume(); /* @endif */
2223
}
2324
return bindContext;
2425
});

src/query/ElementsData.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var ElementsData = (function () {
77
var data = {};
88
var globalId = 1;
9-
9+
1010
function getDataId(element) {
1111
var result = element ? VirtualElement.Is(element) ? element._state ? element._state.attributes[dataIdAttr] : element._attributes[dataIdAttr] :
1212
element.nodeType == 1 ? element.getAttribute(dataIdAttr) :
@@ -49,7 +49,7 @@
4949
var isVirtual = element && element.__identity__ == virtualElementIdentity;
5050
var currentData;
5151
var id;
52-
52+
5353
if (isVirtual) {
5454
currentData = data[element._getAttr(dataIdAttr)];
5555
} else {
@@ -133,7 +133,7 @@
133133
});
134134
data[id] = undefined;
135135
if (VirtualElement.Is(element)) {
136-
element.attr(dataIdAttr, null);
136+
element.removeAttr(dataIdAttr);
137137
} else if (element.nodeType == 1) {
138138
element.removeAttribute(dataIdAttr);
139139
}

src/query/observable.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ define([
5555
};
5656

5757
initialValue = blocks.unwrap(initialValue);
58-
/* @if DEBUG */ blocks.debug.executing = true; /* @endif */
58+
/* @if DEBUG */ blocks.debug.pause(); /* @endif */
5959
blocks.extend(observable, blocks.observable.fn.base);
60-
/* @if DEBUG */ blocks.debug.executing = false; /* @endif */
60+
/* @if DEBUG */ blocks.debug.resume(); /* @endif */
6161
observable.__id__ = observableId++;
6262
observable.__value__ = initialValue;
6363
observable.__context__ = thisArg || blocks.__viewInInitialize__ || observable;
@@ -87,7 +87,9 @@ define([
8787

8888
function updateDependencies(observable) {
8989
if (observable._dependencyType) {
90+
/* @if DEBUG */ blocks.debug.pause(); /* @endif */
9091
observable._getDependency = blocks.bind(getDependency, observable);
92+
/* @if DEBUG */ blocks.debug.resume(); /* @endif */
9193
observable.on('get', observable._getDependency);
9294
}
9395
}

0 commit comments

Comments
 (0)