Skip to content
This repository

better handling of null children #860

Merged
merged 1 commit into from over 1 year ago

3 participants

Drew Folta Caridy Patino Isao Yagi
Drew Folta
Collaborator

No description provided.

Caridy Patino
Owner

+1

Drew Folta drewfish merged commit 53ae3d2 into from
Isao Yagi

need to add /jslint continue:true/ at top or nr the statement(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 13, 2012
Drew Folta drewfish better handling of null children b5e3771
This page is out of date. Refresh to see the latest.
34 lib/app/addons/ac/composite.common.js
@@ -205,8 +205,6 @@ callback({
205 205 buffer = {},
206 206 content = {},
207 207 meta = {},
208   - sanitizedChildren = {},
209   - name,
210 208 perf;
211 209
212 210 cfg.children = cfg.children || {};
@@ -219,20 +217,11 @@ callback({
219 217
220 218 perf = Y.mojito.perf.timeline(NAME, 'execute', Y.Object.keys(cfg.children).join(','), ac.command);
221 219
222   - // check to ensure children doesn't have a null child
223   - // in which case it will be automatically discarded to
224   - // facilitate disabling childs based on the context.
225   - for (name in cfg.children) {
226   - if (cfg.children.hasOwnProperty(name) && cfg.children[name]) {
227   - sanitizedChildren[name] = cfg.children[name];
228   - }
229   - }
230   -
231   - meta.children = sanitizedChildren;
  220 + meta.children = cfg.children;
232 221
233   - buffer.__counter__ = Y.Object.size(sanitizedChildren);
  222 + buffer.__counter__ = Y.Object.size(cfg.children);
234 223
235   - this._dispatchChildren(sanitizedChildren, this.command, buffer,
  224 + this._dispatchChildren(cfg.children, this.command, buffer,
236 225 function() {
237 226 var name;
238 227 // Reference the data we want from the "buffer" into our
@@ -277,6 +266,14 @@ callback({
277 266 for (name in children) {
278 267 if (children.hasOwnProperty(name)) {
279 268 child = children[name];
  269 +
  270 + // check to ensure children doesn't have a null child
  271 + // in which case it will be automatically skipped to
  272 + // facilitate disabling children based on the context.
  273 + if (!child) {
  274 + continue;
  275 + }
  276 +
280 277 // first off, check to see if this child's execution should be
281 278 // deferred
282 279 if (child.defer) {
@@ -315,6 +312,15 @@ callback({
315 312 for (childName in children) {
316 313 if (children.hasOwnProperty(childName)) {
317 314 child = children[childName];
  315 +
  316 + // check to ensure children doesn't have a null child
  317 + // in which case it will be automatically skipped to
  318 + // facilitate disabling children based on the context.
  319 + if (!child) {
  320 + buffer.__counter__ -= 1;
  321 + continue;
  322 + }
  323 +
318 324 // Create a buffer for the child
319 325 buffer[childName] = {name: childName, data: '', meta: {}};
320 326
5 tests/unit/lib/app/addons/ac/test-composite.common.js
@@ -262,9 +262,10 @@ YUI().use('mojito-composite-addon', 'test', function(Y) {
262 262 A.isTrue(exeCbCalled, "execute callback never called");
263 263 },
264 264
265   - 'test null or undefined child should be discarded': function() {
  265 + 'test null or undefined child should be skipped': function() {
266 266 var command = {instance: {}},
267 267 adapter = null,
  268 + countDispatched = 0,
268 269 ac = {
269 270 _dispatch: function(command, adapter) {
270 271 A.isObject(command, "bad command object to dispatch");
@@ -272,6 +273,7 @@ YUI().use('mojito-composite-addon', 'test', function(Y) {
272 273 var id = command.instance.id;
273 274 var meta = {};
274 275 meta[id] = id + '__meta';
  276 + countDispatched += 1;
275 277 adapter.done(id + '__data', meta);
276 278 }, _notify: function() {}
277 279 },
@@ -286,6 +288,7 @@ YUI().use('mojito-composite-addon', 'test', function(Y) {
286 288
287 289 c.execute(config, function(data, meta) {
288 290 exeCbCalled = true;
  291 + A.areSame(1, countDispatched, "dispatched wrong number of children");
289 292 A.isUndefined(data.kid_a, "unexpected kid_a data for null child");
290 293 A.isString(data.kid_b, "missing kid_b data");
291 294 A.areSame('kid_b__data', data.kid_b, "wrong kid_b data");

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.