Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up CoffeeScript translation.

  • Loading branch information...
commit c148aab63a3c8f756b6cee67640771c9fd2a88de 1 parent 67e8223
@jprichardson authored
Showing with 40 additions and 62 deletions.
  1. +40 −62 lib/triggerflow.js
View
102 lib/triggerflow.js
@@ -1,70 +1,48 @@
-// Generated by CoffeeScript 1.3.3
-(function() {
- var TriggerFlow,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
- TriggerFlow = (function() {
+function TriggerFlow() {
+ this.callback = function() {};
+ this.object = {};
+ this.hasTriggered = false;
+}
- function TriggerFlow() {
- this.update = __bind(this.update, this);
- this.callback = function() {};
- this.object = {};
- this.hasTriggered = false;
- }
+TriggerFlow.prototype.update = function(partialObject) {
+ var _this = this
- TriggerFlow.prototype.update = function(partialObject) {
- var allTrue, args, key, val, _ref;
- for (key in partialObject) {
- val = partialObject[key];
- if (partialObject.hasOwnProperty(key)) {
- if (typeof val === 'number') {
- if (val < 0) {
- this.object[key] = this.object[key] + val;
- } else {
- this.object[key] = val;
- }
- } else {
- this.object[key] = val;
- }
- }
- }
- allTrue = true;
- _ref = this.object;
- for (key in _ref) {
- val = _ref[key];
- if (this.object.hasOwnProperty(key)) {
- if (typeof val === 'boolean') {
- allTrue &= val;
- }
- if (typeof val === 'number') {
- allTrue &= val === 0;
- }
- if (!allTrue) {
- return;
- }
- }
- }
- this.hasTriggered = true;
- args = [];
- Array.prototype.push.apply(args, arguments);
- args.shift();
- if (this.callback != null) {
- return this.callback.apply(null, args);
- }
- };
+ Object.keys(partialObject).forEach(function(key) {
+ var val = partialObject[key]
+ if (typeof val === 'number') {
+ if (val < 0) _this.object[key] = _this.object[key] + val
+ else _this.object[key] = val
+ }
+ else
+ _this.object[key] = val
+ })
- TriggerFlow.create = function(object, callback) {
- var tf;
- tf = new TriggerFlow();
- tf.callback = callback;
- tf.object = object;
- return tf;
- };
+ var allTrue = Object.keys(_this.object).map(function(key) { return _this.object[key]}).every(function(val) {
+ if (typeof val === 'boolean') return val;
+ if (typeof val === 'number') return val === 0;
+ else return !!val
+ })
- return TriggerFlow;
+ if (!allTrue) return
- })();
+ this.hasTriggered = true;
+ var args = []
+ Array.prototype.push.apply(args, arguments)
+ args.shift()
+
+ if (this.callback)
+ this.callback.apply(null, args)
+}
+
+TriggerFlow.create = function(object, callback) {
+ var tf = new TriggerFlow()
+ tf.callback = callback
+ tf.object = object
+ return tf
+}
+
+
+module.exports.TriggerFlow = TriggerFlow;
- module.exports.TriggerFlow = TriggerFlow;
-}).call(this);

0 comments on commit c148aab

Please sign in to comment.
Something went wrong with that request. Please try again.