Permalink
Browse files

Merge pull request #186 from misoproject/moving.to.miso.events

moving to miso.events
  • Loading branch information...
2 parents d70a806 + 8013cb9 commit 2c8e9fa433d89335374600ecf6ca7015a391f826 @alexgraul alexgraul committed Nov 16, 2012
View
8 grunt.js
@@ -65,6 +65,7 @@ module.exports = function(grunt) {
"lib/lodash.js",
"lib/underscore.math.js",
"lib/underscore.deferred.js",
+ "lib/miso.events.js",
"dist/miso.ds.<%= pkg.version %>.js"
]
},
@@ -78,6 +79,7 @@ module.exports = function(grunt) {
"lib/json2.js",
"lib/underscore.math.js",
"lib/underscore.deferred.js",
+ "lib/miso.events.js",
"dist/miso.ds.<%= pkg.version %>.js"
]
},
@@ -109,6 +111,10 @@ module.exports = function(grunt) {
"lib/underscore.deferred.js"
],
+ "dist/development/lib/miso.events.js" : [
+ "lib/miso.events.js"
+ ],
+
buildstatus : {
dest : "dist/LASTBUILD",
src : [
@@ -201,8 +207,6 @@ module.exports = function(grunt) {
jshint : {
options : {
- unused : true,
- unuseds : true,
devel : true,
noempty : true,
forin : false,
View
119 lib/miso.events.js
@@ -0,0 +1,119 @@
+(function(global, _) {
+
+ var Miso = global.Miso = (global.Miso || {});
+
+ /**
+ * Miso Events is a small set of methods that can be mixed into any object
+ * to make it evented. It allows one to then subscribe to specific object events,
+ * to publish events, unsubscribe and subscribeOnce.
+ */
+ Miso.Events = {
+
+ /**
+ * Triggers a specific event and passes any additional arguments
+ * to the callbacks subscribed to that event.
+ * Params:
+ * name - the name of the event to trigger
+ * .* - any additional arguments to pass to callbacks.
+ */
+ publish : function(name) {
+ var args = _.toArray(arguments);
+ args.shift();
+
+ if (this._events && this._events[name]) {
+ _.each(this._events[name], function(subscription) {
+ subscription.callback.apply(subscription.context || this, args);
+ }, this);
+ }
+ return this;
+ },
+
+ /**
+ * Allows subscribing on an evented object to a specific name.
+ * Provide a callback to trigger.
+ * Params:
+ * name - event to subscribe to
+ * callback - callback to trigger
+ * options - optional arguments
+ * priority - allows rearranging of existing callbacks based on priority
+ * context - allows attaching diff context to callback
+ * token - allows callback identification by token.
+ */
+ subscribe : function(name, callback, options) {
+ options = options || {};
+ this._events = this._events || {};
+ this._events[name] = this._events[name] || [];
+
+ var subscription = {
+ callback : callback,
+ priority : options.priority || 0,
+ token : options.token || _.uniqueId('t'),
+ context : options.context || this
+ };
+ var position;
+ _.each(this._events[name], function(event, index) {
+ if (!_.isUndefined(position)) { return; }
+ if (event.priority <= subscription.priority) {
+ position = index;
+ }
+ });
+
+ this._events[name].splice(position, 0, subscription);
+ return subscription.token;
+ },
+
+ /**
+ * Allows subscribing to an event once. When the event is triggered
+ * this subscription will be removed.
+ * Params:
+ * name - name of event
+ * callback - The callback to trigger
+ * options - optional arguments
+ * priority - allows rearranging of existing callbacks based on priority
+ * context - allows attaching diff context to callback
+ * token - allows callback identification by token.
+ */
+ subscribeOnce : function(name, callback, options) {
+ this._events = this._events || {};
+ options = options || {};
+ var self = this;
+
+ if (typeof options.token === "undefined") {
+ options.token = _.uniqueId('t');
+ }
+
+ return this.subscribe(name, function() {
+ self.unsubscribe(name, { token : options.token });
+ callback.apply(this, arguments);
+ }, options);
+ },
+
+ /**
+ * Allows unsubscribing from a specific event
+ * Params:
+ * name - event to unsubscribe from
+ * identifier - callback to remove OR token.
+ */
+ unsubscribe : function(name, identifier) {
+
+ if (_.isUndefined(this._events[name])) { return this; }
+
+ if (_.isFunction(identifier)) {
+ this._events[name] = _.reject(this._events[name], function(b) {
+ return b.callback === identifier;
+ });
+
+ } else if ( _.isString(identifier)) {
+ this._events[name] = _.reject(this._events[name], function(b) {
+ return b.token === identifier;
+ });
+
+ } else {
+ this._events[name] = [];
+ }
+ return this;
+ }
+
+ };
+
+}(this, _));
View
3 package.json
@@ -38,6 +38,7 @@
"lodash": "0.9.0",
"moment": "1.7.2",
"underscore.deferred": "0.2.0",
- "request": "2.9.153"
+ "request": "2.9.153",
+ "miso.events" : "*"
}
}
View
23 src/dataset.js
@@ -7,6 +7,7 @@ Version 0.0.1.2
(function(global, _, moment) {
+ var Miso = global.Miso || (global.Miso = {});
var Dataset = global.Miso.Dataset;
// take on miso dataview's prototype
@@ -25,7 +26,7 @@ Version 0.0.1.2
// is this a syncable dataset? if so, pull
// required methods and mark this as a syncable dataset.
if (options.sync === true) {
- _.extend(this, Dataset.Events);
+ _.extend(this, Miso.Events);
this.syncable = true;
}
@@ -453,9 +454,9 @@ Version 0.0.1.2
}, this);
if (this.syncable && !options.silent) {
- var e = this._buildEvent(deltas, this);
- this.trigger('add', e );
- this.trigger('change', e );
+ var e = Dataset.Events._buildEvent(deltas, this);
+ this.publish('add', e );
+ this.publish('change', e );
}
return this;
@@ -487,9 +488,9 @@ Version 0.0.1.2
}, this);
if (this.syncable && (!options || !options.silent)) {
- var ev = this._buildEvent( deltas, this );
- this.trigger('remove', ev );
- this.trigger('change', ev );
+ var ev = Dataset.Events._buildEvent( deltas, this );
+ this.publish('remove', ev );
+ this.publish('change', ev );
}
},
@@ -589,9 +590,9 @@ Version 0.0.1.2
//computer column updates
//update triggers
if (this.syncable && (!options || !options.silent)) {
- var ev = this._buildEvent( deltas, this );
- this.trigger('update', ev );
- this.trigger('change', ev );
+ var ev = Dataset.Events._buildEvent( deltas, this );
+ this.publish('update', ev );
+ this.publish('change', ev );
}
return this;
},
@@ -609,7 +610,7 @@ Version 0.0.1.2
});
this.length = 0;
if (this.syncable && (!options || !options.silent)) {
- this.trigger("reset");
+ this.publish("reset");
}
}
View
16 src/derived.js
@@ -1,6 +1,7 @@
(function(global, _) {
- var Dataset = global.Miso.Dataset;
+ var Miso = global.Miso || (global.Miso = {});
+ var Dataset = Miso.Dataset;
/**
* A Miso.Derived dataset is a regular dataset that has been derived
@@ -40,9 +41,9 @@
});
if (this.parent.syncable) {
- _.extend(this, Dataset.Events);
+ _.extend(this, Miso.Events);
this.syncable = true;
- this.parent.bind("change", this._sync, this);
+ this.parent.subscribe("change", this._sync, { context : this });
}
};
@@ -51,11 +52,11 @@
// inherit all of dataset's methods.
_.extend(Dataset.Derived.prototype, {
- _sync : function(event) {
+ _sync : function() {
// recompute the function on an event.
// TODO: would be nice to be more clever about this at some point.
this.func.call(this.args);
- this.trigger("change");
+ this.publish("change");
}
});
@@ -102,7 +103,6 @@
// apply with the arguments columns, size, method
var computeMovingAverage = function() {
- var win = [];
// normalize columns arg - if single string, to array it.
if (typeof columns === "string") {
@@ -115,7 +115,7 @@
.data.slice(size-1, this.parent.length);
// copy the columns we are NOT combining minus the sliced size.
- this.eachColumn(function(columnName, column, i) {
+ this.eachColumn(function(columnName, column) {
if (columns.indexOf(columnName) === -1 && columnName !== "_oids") {
// copy data
column.data = this.parent.column(columnName).data.slice(size-1, this.parent.length);
@@ -258,7 +258,6 @@
// a cache of values
var categoryPositions = {},
categoryCount = 0,
- byColumnPosition = this._columnPositionByName[byColumn],
originalByColumn = this.parent.column(byColumn);
// bin all values by their
@@ -297,7 +296,6 @@
_.each(columns, function(columnToGroup) {
var column = this.column(columnToGroup),
- value = this.parent.column(columnToGroup).data[i],
binPosition = categoryPositions[category];
column.data[binPosition].push(this.parent.rowByPosition(i));
View
18 src/node/compat.js
@@ -4,28 +4,14 @@ var moment = require("moment");
_.mixin(require("underscore.deferred"));
var request = require("request");
+this.Miso = require("miso.events");
+
// Include underscore math
<%= underscoreMath %>
// Include Miso Dataset lib
<%= misoDataSet %>
-// Load function that makes Miso plugin loading more formal.
-this.Miso.load = function(moduleName) {
- try {
- // Attempt to load from node_modules
- require(moduleName);
- } catch (ex) {
- // If path is not already full qualified prefix with cwd
- if (!path.existsSync(moduleName)) {
- moduleName = path.resolve(process.cwd(), moduleName);
- }
-
- // Load the correct module
- require(moduleName);
- }
-};
-
// Ensure compatibility with Remote Importer
this.Miso.Xhr = function(options) {
// Make the request using the request module
View
2 src/parsers/google_spreadsheet.js
@@ -70,7 +70,7 @@
var positionRegex = /([A-Z]+)(\d+)/,
columnPositions = {};
- _.each(data.feed.entry, function(cell, index) {
+ _.each(data.feed.entry, function(cell) {
var parts = positionRegex.exec(cell.title.$t),
column = parts[1],
View
9 src/product.js
@@ -1,5 +1,6 @@
(function(global, _) {
+ var Miso = global.Miso || (global.Miso = {});
var Dataset = global.Miso.Dataset;
/**
@@ -36,7 +37,7 @@
return this;
};
- _.extend(Dataset.Product.prototype, Dataset.Events, {
+ _.extend(Dataset.Product.prototype, Miso.Events, {
/**
* return the raw value of the product
@@ -94,14 +95,14 @@
var delta = this._buildDelta(this.value, producer.call(_self));
this.value = delta.changed;
if (_self.syncable) {
- var event = this._buildEvent(delta, this);
+ var event = Dataset.Events._buildEvent(delta, this);
if (!_.isUndefined(delta.old) && !options.silent && delta.old !== delta.changed) {
- this.trigger("change", event);
+ this.publish("change", event);
}
}
}
});
- this.bind("change", prod._sync, prod);
+ this.subscribe("change", prod._sync, { context : prod });
return prod;
} else {
View
77 src/sync.js
@@ -74,84 +74,9 @@
//Event Related Methods
Dataset.Events = {};
- /**
- * Bind callbacks to dataset events
- * Parameters:
- * ev - name of the event
- * callback - callback function
- * context - context for the callback. optional.
- * Returns
- * object being bound to.
- */
- Dataset.Events.bind = function (ev, callback, context) {
- var calls = this._callbacks || (this._callbacks = {});
- var list = calls[ev] || (calls[ev] = {});
- var tail = list.tail || (list.tail = list.next = {});
- tail.callback = callback;
- tail.context = context;
- list.tail = tail.next = {};
- return this;
- };
-
- /**
- * Remove one or many callbacks. If `callback` is null, removes all
- * callbacks for the event. If `ev` is null, removes all bound callbacks
- * for all events.
- * Parameters:
- * ev - event name
- * callback - Optional. callback function to be removed
- * Returns:
- * The object being unbound from.
- */
- Dataset.Events.unbind = function(ev, callback) {
- var calls, node, prev;
- if (!ev) {
- this._callbacks = null;
- } else if (calls = this._callbacks) {
- if (!callback) {
- calls[ev] = {};
- } else if (node = calls[ev]) {
- while ((prev = node) && (node = node.next)) {
- if (node.callback !== callback) {
- continue;
- }
- prev.next = node.next;
- node.context = node.callback = null;
- break;
- }
- }
- }
- return this;
- };
-
- /**
- * trigger a given event
- * Parameters:
- * eventName - name of event
- * Returns;
- * object being triggered on.
- */
- Dataset.Events.trigger = function(eventName) {
- var node, calls, callback, args, ev, events = ['all', eventName];
- if (!(calls = this._callbacks)) {
- return this;
- }
- while (ev = events.pop()) {
- if (!(node = calls[ev])) {
- continue;
- }
- args = ev === 'all' ? arguments : Array.prototype.slice.call(arguments, 1);
- while (node = node.next) {
- if (callback = node.callback) {
- callback.apply(node.context || this, args);
- }
- }
- }
- return this;
- };
-
// Used to build event objects accross the application.
Dataset.Events._buildEvent = function(delta, dataset) {
return new Dataset.Event(delta, dataset);
};
+
}(this, _));
View
4 src/types.js
@@ -29,7 +29,7 @@
}
return v;
},
- test : function(v) {
+ test : function() {
return true;
},
compare : function(s1, s2) {
@@ -192,7 +192,7 @@
// if string, then parse as a time
if (_.isString(v)) {
var format = options.format || this.format;
- return moment(v, options.format);
+ return moment(v, format);
} else if (_.isNumber(v)) {
return moment(v);
} else {
View
13 src/view.js
@@ -1,5 +1,6 @@
(function(global, _) {
+ var Miso = global.Miso || (global.Miso = {});
var Dataset = global.Miso.Dataset;
/**
@@ -159,7 +160,7 @@
// is this a syncable dataset? if so, pull
// required methoMiso and mark this as a syncable dataset.
if (this.parent.syncable === true) {
- _.extend(this, Dataset.Events);
+ _.extend(this, Miso.Events);
this.syncable = true;
}
@@ -178,7 +179,7 @@
// bind to parent if syncable
if (this.syncable) {
- this.parent.bind("change", this._sync, this);
+ this.parent.subscribe("change", this._sync, { context : this });
}
},
@@ -252,8 +253,8 @@
// trigger any subscribers
if (this.syncable) {
- this.trigger(eventType, event);
- this.trigger("change", event);
+ this.publish(eventType, event);
+ this.publish("change", event);
}
},
@@ -512,7 +513,7 @@
return this;
},
- _add : function(row, options) {
+ _add : function(row) {
// first coerce all the values appropriatly
_.each(row, function(value, key) {
@@ -678,7 +679,7 @@
}
if (this.syncable && !options.silent) {
- this.trigger("sort");
+ this.publish("sort");
}
return this;
View
1 test/index.html
@@ -10,6 +10,7 @@
<script src="../lib/underscore.math.js"></script>
<script src="../lib/underscore.deferred.js"></script>
<script src="../lib/moment.js"></script>
+ <script src="../lib/miso.events.js"></script>
<!-- test script for checking the namespace isn't overwritten -->
<script type='text/javascript'>
View
7 test/unit/bugs.js
@@ -1,8 +1,7 @@
(function(global) {
- var Util = global.Util;
var Miso = global.Miso || {};
- var Dataset = global.Miso.Dataset;
+ var Dataset = Miso.Dataset;
module("Bugs");
@@ -342,7 +341,7 @@
ok(_.isEqual(gb.column("e").data, [1]));
ok(_.isEqual(gb.column("x").data, [3]));
- gb.bind("change", function() {
+ gb.subscribe("change", function() {
equals(gb.length, 2);
ok(_.isEqual(gb.column("q").data, [3,50]));
ok(_.isEqual(gb.column("e").data, [1,12]));
@@ -397,7 +396,7 @@
start();
}
},
- error : function(r) {
+ error : function() {
start();
ok(false);
}
View
9 test/unit/dataset.js
@@ -121,7 +121,6 @@
test("updating a row with a custom idAttribute (updating id col)", 1, function() {
var ds = Util.baseSampleCustomID();
- var firstRowId = ds.rowByPosition(0).one;
raises(function() {
ds.update({ one : 99});
@@ -425,12 +424,12 @@
ds.fetch().then(function() {
ok(_.isEqual(ds.columnNames(), ["one", "two"]));
- var newcol = ds.addComputedColumn("three", "number", function(row) {
+ ds.addComputedColumn("three", "number", function(row) {
return row.one + row.two;
});
stop();
- ds.bind("add", function(event) {
+ ds.subscribe("add", function(event) {
ok(event.deltas[0].changed.three === 44);
start();
});
@@ -456,12 +455,12 @@
ds.fetch().then(function() {
ok(_.isEqual(ds.columnNames(), ["one", "two"]));
- var newcol = ds.addComputedColumn("three", "number", function(row) {
+ ds.addComputedColumn("three", "number", function(row) {
return row.one + row.two;
});
stop();
- ds.bind("change", function(event) {
+ ds.subscribe("change", function(event) {
ok(event.deltas[0].changed.three === 110);
start();
});
View
26 test/unit/derived.js
@@ -1,8 +1,6 @@
(function(global) {
- var Util = global.Util;
var Miso = global.Miso || {};
- var Dataset = Miso.Dataset;
module("CountBy");
var countData = {
@@ -272,28 +270,6 @@
};
}
- function getGroupByData() {
- return {
- columns : [
- {
- name : "state",
- type : "string",
- data : ["AZ", "MA"]
- },
- {
- name : "count",
- type : "number",
- data : [6,15]
- },
- {
- name : "anothercount",
- type : "number",
- data : [60,150]
- }
- ]
- };
- }
-
test("base group by", function() {
var ds = new Miso.Dataset({
@@ -481,7 +457,7 @@
ok(_.isEqual(groupedData._columns[4].data, [60,150]), "anothercounts correct" + groupedData._columns[3].data);
groupedData = ds.groupBy("state", ["count", "anothercount"], {
- preprocess : function(state) {
+ preprocess : function() {
return "A";
}
});
View
21 test/unit/events.js
@@ -1,6 +1,5 @@
(function(global) {
- var Util = global.Util;
var Miso = global.Miso || {};
module("Events");
@@ -18,10 +17,10 @@
result += by;
};
- ds.bind('ping', increment);
+ ds.subscribe('ping', increment);
result = 0;
- ds.trigger('ping', 1);
+ ds.publish('ping', 1);
equals(result, 1);
});
@@ -37,11 +36,11 @@
result += by;
};
- ds.bind('ping', increment);
+ ds.subscribe('ping', increment);
- ds.trigger('ping');
- ds.unbind('ping', increment);
- ds.trigger('ping');
+ ds.publish('ping');
+ ds.unsubscribe('ping', increment);
+ ds.publish('ping');
equals(result, 1);
});
@@ -55,7 +54,7 @@
sync : true
});
ds.fetch({ success: function() {
- this.bind('add', function(event) {
+ this.subscribe('add', function(event) {
equals( event.affectedColumns().length, 1);
ok( event.affectedColumns()[0] === 'one' );
});
@@ -74,7 +73,7 @@
sync : true
});
ds.fetch({ success: function() {
- this.bind('remove', function(event) {
+ this.subscribe('remove', function(event) {
equals( event.affectedColumns().length, 1);
ok( event.affectedColumns()[0] === 'one' );
});
@@ -93,7 +92,7 @@
sync : true
});
ds.fetch({ success: function() {
- this.bind('change', function(event) {
+ this.subscribe('change', function(event) {
equals( event.affectedColumns().length, 1);
ok( event.affectedColumns()[0] === 'one' );
});
@@ -116,7 +115,7 @@
sync : true
});
ds.fetch({ success: function() {
- this.bind('change', function(event) {
+ this.subscribe('change', function(event) {
equals( event.affectedColumns().length, 1);
ok( event.affectedColumns()[0] === 'one' );
});
View
9 test/unit/importers.js
@@ -1,6 +1,5 @@
(function(global) {
- var Util = global.Util;
var Miso = global.Miso || {};
var Dataset = Miso.Dataset;
@@ -624,7 +623,7 @@
});
// check data size
- ds.eachColumn(function(cn, c, i) {
+ ds.eachColumn(function(cn, c) {
equals(c.data.length, expectedSize);
});
@@ -706,11 +705,11 @@
});
}
- ds.bind('update', function(event) {
+ ds.subscribe('update', function(event) {
events.push(event.deltas);
});
- ds.bind('add', function(event) {
+ ds.subscribe('add', function(event) {
addEvents.push(event.deltas);
});
@@ -751,7 +750,7 @@
madereqs++;
counter += 1;
},
- error : function(r) {
+ error : function() {
console.log('ERROR', arguments);
}
});
View
27 test/unit/products.js
@@ -73,9 +73,6 @@
//empty
equals(ds.max().val(), 9);
- var names = _.compact(_.map(ds._columns, function(column) {
- if (column.name !== "_id") {return column.name;}
- }));
ok(ds.max(ds.columnNames()).val() === 9);
@@ -94,9 +91,6 @@
//empty
equals(ds.max(), 9);
- var names = _.compact(_.map(ds._columns, function(column) {
- if (column.name !== "_id") {return column.name;}
- }));
ok(ds.max(ds.columnNames()) === 9);
});
@@ -154,9 +148,6 @@
//empty
equals(ds.min().val(), 1);
- var names = _.compact(_.map(ds._columns, function(column) {
- if (column.name !== "_id") {return column.name;}
- }));
});
test("Basic Min Product Non Syncable", function() {
@@ -241,17 +232,17 @@
equals(m3.val(), 5.5);
equals(ds.mean(['vals', 'valsrandomorder', 'randomvals']).val(), 18.4);
- m.bind("change", function(s) {
+ m.subscribe("change", function(s) {
equals(s.deltas[0].old, 5.5);
equals(this.val(), 6.4);
});
- m2.bind("change", function(s) {
+ m2.subscribe("change", function(s) {
equals(s.deltas[0].old, 5.5);
equals(this.val(), 6.4);
});
- m3.bind("change", function(s) {
+ m3.subscribe("change", function(s) {
equals(s.deltas[0].old, 5.5);
equals(this.val(), 5.95);
});
@@ -310,7 +301,7 @@
var meantime = ds.mean("t");
equals(meantime.val().format("YYYYMMDD"), moment("2010/01/15").format("YYYYMMDD"));
- meantime.bind("change", function() {
+ meantime.subscribe("change", function() {
equals(meantime.val().format("YYYYMMDD"), moment("2010/01/10").format("YYYYMMDD"));
});
@@ -350,10 +341,9 @@
test("Basic subscription to product changes", function() {
var ds = Util.baseSyncingSample(),
max = ds.max("one"),
- maxFunc = ds.max("one"),
counter = 0;
- max.bind('change', function() {
+ max.subscribe('change', function() {
counter += 1;
});
@@ -366,10 +356,9 @@
test("Basic subscription to product changes on syncable doesn't trigger", function() {
var ds = Util.baseSample(),
- max = ds.max("one"),
- counter = 0;
+ max = ds.max("one");
- equals(_.isUndefined(max.bind), true);
+ equals(_.isUndefined(max.subscribe), true);
equals(Dataset.typeOf(max), "number");
});
@@ -379,7 +368,7 @@
max = ds.max("one"),
counter = 0;
- max.bind('change', function() {
+ max.subscribe('change', function() {
counter += 1;
});
View
1 test/unit/types.js
@@ -1,6 +1,5 @@
(function(global) {
- var Util = global.Util;
var Dataset = global.Miso.Dataset;
var numbers = ['123', '0.34', '.23'];
View
28 test/unit/views.js
@@ -211,7 +211,7 @@
test("Function Row Filter View creation with computed product", function() {
var ds = Util.baseSample();
var view = ds.where({
- rows : function(row) {
+ rows : function() {
return true;
}
});
@@ -224,7 +224,7 @@
test("Function Row Filter View creation with computed product with custom idAttribute", function() {
var ds = Util.baseSampleCustomID();
var view = ds.where({
- rows : function(row) {
+ rows : function() {
return true;
}
});
@@ -359,7 +359,7 @@ module("Views :: Rows Selection");
};
var count = 0;
- ds.reverseEach(function(row, index) {
+ ds.reverseEach(function(row) {
if (count === 0) {
ok(_.isEqual(row, expectedRow), "Row by position is equal");
}
@@ -432,9 +432,9 @@ module("Views :: Syncing");
var event = Dataset.Events._buildEvent(delta);
- // trigger view sync with delta
+ // publish view sync with delta
// view.sync(delta);
- ds.trigger("change", event);
+ ds.publish("change", event);
// make sure view updated
ok(view._columns[colPos].data[0] === 100, "view was updated to " + view._columns[colPos].data[0]);
@@ -468,13 +468,11 @@ module("Views :: Syncing");
};
delta.old[col] = oldVal;
delta.changed[col] = 100;
-
- var event = Dataset.Events._buildEvent(delta);
- // trigger view sync with delta
+ // publish view sync with delta
// view.sync(delta);
- if (_.isUndefined(ds.trigger)) {
- ok(true, "can't even trigger change, no trigger api.");
+ if (_.isUndefined(ds.publish)) {
+ ok(true, "can't even trigger change, no publish api.");
}
// make sure view updated
@@ -539,7 +537,7 @@ module("Views :: Syncing");
var event = Dataset.Events._buildEvent(delta);
// trigger dataset change
- ds.trigger("change", event);
+ ds.publish("change", event);
// verify both views have updated
ok(view._columns[1].data[0] === 100, "first view updated");
@@ -549,8 +547,6 @@ module("Views :: Syncing");
test("Basic row removal propagation", function() {
var ds = Util.baseSyncingSample();
- var colname = ds._columns[1].name;
- var rowPos = 0;
// make a view for first two rows
var view = ds.where({
@@ -569,7 +565,7 @@ module("Views :: Syncing");
// delete actual row
ds._remove( ds._rowIdByPosition[0] );
- ds.trigger("change", event);
+ ds.publish("change", event);
// verify view row was deleted as well
ok(view.length === 1, "view is one element shorter");
@@ -617,7 +613,7 @@ module("Views :: Syncing");
// for now, we aren't adding the actual data to the original dataset
// just simulating that addition. Eventually when we ammend the api
// with .add support, this can be refactored. better yet, added to.
- ds.trigger("change", event);
+ ds.publish("change", event);
ok(view.length === 4, "row was added");
ok(_.isEqual(view.rowByPosition(3), newRow), "rows are equal");
@@ -658,7 +654,7 @@ module("Views :: Syncing");
// for now, we aren't adding the actual data to the original dataset
// just simulating that addition. Eventually when we ammend the api
// with .add support, this can be refactored. better yet, added to.
- ds.trigger("change", event);
+ ds.publish("change", event);
ok(view.length === 3, "row was NOT added");

0 comments on commit 2c8e9fa

Please sign in to comment.