Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

playing around

  • Loading branch information...
commit 33f7cfb225ac284d6ed5f783caa54552b0c0248e 1 parent cac3045
@drewlesueur authored
Showing with 66 additions and 12 deletions.
  1. +30 −4 drews-mixins.coffee
  2. +24 −8 drews-mixins.js
  3. +12 −0 test.coffee
View
34 drews-mixins.coffee
@@ -97,7 +97,7 @@ goAndDo = (exports, _) ->
exports.on = (obj, ev, callback) ->
calls = obj._callbacks || obj._callbacks = {}
- list = calls[ev] || (calls[ev] = {})
+ list = calls[ev] || (calls[ev] = [])
list.push callback
obj._events = obj._callbacks
obj
@@ -117,16 +117,19 @@ goAndDo = (exports, _) ->
# list[i] = null #backbone.js
break
obj
-
+ #TODO async events? wait 0, ->
exports.emit = (obj, eventName, args...) ->
both = 2
+ id = _.uniqueId()
if !(calls = obj._callbacks) then return obj
while both--
- ev = both ? eventName : "all"
+ ev = if both then eventName else "all"
+ list = calls[ev]
+
if list=calls[ev]
for item, i in list
callback = list[i]
- args = both ? args : args.unshift(eventName)
+ args = if both then args else args.unshift(eventName)
# maby have obj as the first param?
callback.apply obj, args
exports.trigger = exports.emit
@@ -256,6 +259,29 @@ goAndDo = (exports, _) ->
obj[key] = []
obj[key].push value
+
+ #maybe to one for add to array
+ addToObject = (obj, key, value) ->
+ obj[key] = value
+ addToObjectMaker = (obj) ->
+ (key, value) ->
+ addToObject obj, key, value
+ exports.addToObjectMaker = addToObjectMaker
+
+ # asyncTests = (batches, tests) ->
+ # before = addToObjectMaker()
+ # test = addToObjectMaker()
+ # prepareTests = () ->
+ # _.series batches
+ ###
+ do ->
+ giveBackTheCard = takeACard()
+
+
+
+ giveBackTheCard()
+ ###
+
exports.getAssertCount = -> count
exports.getFailCount = -> failCount
exports.getPassCount = -> passCount
View
32 drews-mixins.js
@@ -61,6 +61,7 @@
*/
goAndDo = function(exports, _) {
+ var addToObject, addToObjectMaker;
exports.asyncEx = function(len, cb) {
return _.wait(len, function() {
return cb(null, len);
@@ -108,7 +109,7 @@
exports.on = function(obj, ev, callback) {
var calls, list;
calls = obj._callbacks || (obj._callbacks = {});
- list = calls[ev] || (calls[ev] = {});
+ list = calls[ev] || (calls[ev] = []);
list.push(callback);
obj._events = obj._callbacks;
return obj;
@@ -138,17 +139,17 @@
return obj;
};
exports.emit = function() {
- var args, both, callback, calls, ev, eventName, i, item, list, obj, _results;
+ var args, both, callback, calls, ev, eventName, i, id, item, list, obj, _results;
obj = arguments[0], eventName = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
both = 2;
+ id = _.uniqueId();
if (!(calls = obj._callbacks)) {
return obj;
}
_results = [];
while (both--) {
- ev = both != null ? both : {
- eventName: "all"
- };
+ ev = both ? eventName : "all";
+ list = calls[ev];
_results.push((function() {
var _len, _results2;
if (list = calls[ev]) {
@@ -156,9 +157,7 @@
for (i = 0, _len = list.length; i < _len; i++) {
item = list[i];
callback = list[i];
- args = both != null ? both : {
- args: args.unshift(eventName)
- };
+ args = both ? args : args.unshift(eventName);
_results2.push(callback.apply(obj, args));
}
return _results2;
@@ -310,6 +309,23 @@
}
return obj[key].push(value);
};
+ addToObject = function(obj, key, value) {
+ return obj[key] = value;
+ };
+ addToObjectMaker = function(obj) {
+ return function(key, value) {
+ return addToObject(obj, key, value);
+ };
+ };
+ exports.addToObjectMaker = addToObjectMaker;
+ /*
+ do ->
+ giveBackTheCard = takeACard()
+
+
+
+ giveBackTheCard()
+ */
exports.getAssertCount = function() {
return count;
};
View
12 test.coffee
@@ -11,7 +11,19 @@ _.mixin nimble
asyncEx
wait
isEqual
+ addToObjectMaker
} = _
+tests = {}
+befores = {}
+test = addToObjectMaker tests
+before = addToObjectMaker befores
+
+stuff = {}
+addToObj = addToObjectMaker stuff
+addToObj "name", "aterciopelados"
+addToObj "cd", "rio"
+eq stuff.name, "aterciopelados", "name should be aterciopelados"
+
str = "this is a test"
sub = s str, 2, 2
eq sub, "is"
Please sign in to comment.
Something went wrong with that request. Please try again.