jskit_rails 3.4.2 → 3.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/jskit.js +107 -0
- data/app/assets/javascripts/jskit.min.js +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ebb46afcc2201410e1f0e3af3319c108d7eede5
|
4
|
+
data.tar.gz: 532e38be4139010c99e4fd5d0ea72bda2b5aeb00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e4a8f0df3d0ad43721046efd60168a8a4e6d6205e36bcb23d6bfa8ef136908f6141547e3a68838827451827bc522f7d5400b75afdf3715a8d501e19b5fa6df1
|
7
|
+
data.tar.gz: 23e7b142294bee356a16ed4ba2e662d1bd8229ce3869a671169f1a31461002d25984e7029dc15449643c4ec499b87fb7f6f037e7336925278ed295feafcff4a4
|
@@ -47,6 +47,113 @@ JSKit.Dispatcher = (function() {
|
|
47
47
|
return Dispatcher;
|
48
48
|
})();
|
49
49
|
|
50
|
+
JSKit.TestDispatcher = (function() {
|
51
|
+
var assign = _.assign;
|
52
|
+
var clone = _.clone;
|
53
|
+
var contains = _.contains;
|
54
|
+
var each = _.each;
|
55
|
+
var first = _.first;
|
56
|
+
var functions = _.functions;
|
57
|
+
var isString = _.isString;
|
58
|
+
var keys = _.keys;
|
59
|
+
var map = _.map;
|
60
|
+
var rest = _.rest;
|
61
|
+
var toArray = _.toArray;
|
62
|
+
var values = _.values;
|
63
|
+
|
64
|
+
function spyOn(handler) {
|
65
|
+
handler.called = false;
|
66
|
+
handler.callCount = 0;
|
67
|
+
handler.calls = [];
|
68
|
+
return handler;
|
69
|
+
}
|
70
|
+
|
71
|
+
function mapAction(action) {
|
72
|
+
var name;
|
73
|
+
var method;
|
74
|
+
|
75
|
+
name = isString(action) ? action : first(keys(action));
|
76
|
+
method = isString(action) ? action : first(values(action));
|
77
|
+
|
78
|
+
return { name: name, method: method };
|
79
|
+
}
|
80
|
+
|
81
|
+
function actionName(action) {
|
82
|
+
var actionMap = mapAction(action);
|
83
|
+
return isString(action) ? '"' + action + '"' : '{ ' + actionMap.name + ': "' + actionMap.method + '" }';
|
84
|
+
}
|
85
|
+
|
86
|
+
function TestDispatcher() {
|
87
|
+
this.listeners = [];
|
88
|
+
this.events = {};
|
89
|
+
this.shadowDispatcher = new JSKit.Dispatcher;
|
90
|
+
}
|
91
|
+
|
92
|
+
assign(TestDispatcher.prototype, {
|
93
|
+
on: function(eventName, handler, controller) {
|
94
|
+
if (!contains(this.listeners, controller)) this.spyOnControllerMethods(controller);
|
95
|
+
var spy = spyOn(handler);
|
96
|
+
|
97
|
+
this.events[eventName] = this.events[eventName] || [];
|
98
|
+
this.events[eventName].push(spy);
|
99
|
+
|
100
|
+
this.shadowDispatcher.on(eventName, function() {
|
101
|
+
this.trackSpy(spy, arguments);
|
102
|
+
}, this);
|
103
|
+
},
|
104
|
+
|
105
|
+
spyOnControllerMethods: function(controller) {
|
106
|
+
var actionNames = map(controller.actions, function(action) { return actionName(action); });
|
107
|
+
var _this = this;
|
108
|
+
each(functions(controller), function(method) {
|
109
|
+
if (!contains(actionNames, method)) {
|
110
|
+
var unboundMethod = controller[method];
|
111
|
+
controller[method] = function() {
|
112
|
+
_this.trackSpy(controller[method], arguments);
|
113
|
+
return unboundMethod.apply(controller, arguments);
|
114
|
+
};
|
115
|
+
spyOn(controller[method]);
|
116
|
+
}
|
117
|
+
}, this);
|
118
|
+
this.listeners.push(controller);
|
119
|
+
},
|
120
|
+
|
121
|
+
trigger: function(eventName, handler, context) {
|
122
|
+
this.shadowDispatcher.trigger(eventName, handler, context);
|
123
|
+
},
|
124
|
+
|
125
|
+
trackSpy: function(spy, args) {
|
126
|
+
spy.callCount += 1;
|
127
|
+
spy.called = true;
|
128
|
+
spy.calls.push({ args: toArray(args) });
|
129
|
+
},
|
130
|
+
|
131
|
+
hasAction: function(controller, action) {
|
132
|
+
var actionExists = false;
|
133
|
+
|
134
|
+
controller.actions.forEach(function(a) {
|
135
|
+
if (actionName(a) === actionName(action)) actionExists = true;
|
136
|
+
});
|
137
|
+
|
138
|
+
if (!actionExists) return false;
|
139
|
+
|
140
|
+
var actionMap = mapAction(action);
|
141
|
+
var handler = controller[actionMap.method];
|
142
|
+
|
143
|
+
var eventName = controller.actionEventName(actionMap.name);
|
144
|
+
var cachedCount = handler.callCount;
|
145
|
+
|
146
|
+
controller.dispatcher.trigger(eventName);
|
147
|
+
|
148
|
+
return handler.callCount > cachedCount;
|
149
|
+
},
|
150
|
+
|
151
|
+
off: function() {}
|
152
|
+
});
|
153
|
+
|
154
|
+
return TestDispatcher;
|
155
|
+
})();
|
156
|
+
|
50
157
|
JSKit.Controller = (function() {
|
51
158
|
var bindAll = _.bindAll;
|
52
159
|
var compact = _.compact;
|
@@ -1 +1 @@
|
|
1
|
-
var JSKit={};JSKit.Dispatcher=function(){function t(){this.__events__={}}return _.assign(t.prototype,{on:function(t,n,e){var i={context:e||null,handler:n},r=this.__events__[t]=this.__events__[t]||[];_.contains(_.pluck(r,"handler"),n)||r.push(i)},off:function(t,n){var e=this.__events__[t];this.__events__[t]=n?_.reject(e,function(t){return t.handler!==n}):[]},trigger:function(t){var n=this.__events__[t]||[],e=_.rest(arguments);_.each(n,function(t){var n=t.handler,i=t.context;n.apply(i,e)})}}),t}(),JSKit.Controller=function(){function t(t,n){if(!t)throw new Error(this.className+": dispatcher is undefined");
|
1
|
+
var JSKit={};JSKit.Dispatcher=function(){function t(){this.__events__={}}return _.assign(t.prototype,{on:function(t,n,e){var i={context:e||null,handler:n},r=this.__events__[t]=this.__events__[t]||[];_.contains(_.pluck(r,"handler"),n)||r.push(i)},off:function(t,n){var e=this.__events__[t];this.__events__[t]=n?_.reject(e,function(t){return t.handler!==n}):[]},trigger:function(t){var n=this.__events__[t]||[],e=_.rest(arguments);_.each(n,function(t){var n=t.handler,i=t.context;n.apply(i,e)})}}),t}(),JSKit.TestDispatcher=function(){function t(t){return t.called=!1,t.callCount=0,t.calls=[],t}function n(t){var n,e;return n=h(t)?t:a(l(t)),e=h(t)?t:a(f(t)),{name:n,method:e}}function e(t){var e=n(t);return h(t)?'"'+t+'"':"{ "+e.name+': "'+e.method+'" }'}function i(){this.listeners=[],this.events={},this.shadowDispatcher=new JSKit.Dispatcher}var r=_.assign,s=(_.clone,_.contains),o=_.each,a=_.first,c=_.functions,h=_.isString,l=_.keys,u=_.map,p=(_.rest,_.toArray),f=_.values;return r(i.prototype,{on:function(n,e,i){s(this.listeners,i)||this.spyOnControllerMethods(i);var r=t(e);this.events[n]=this.events[n]||[],this.events[n].push(r),this.shadowDispatcher.on(n,function(){this.trackSpy(r,arguments)},this)},spyOnControllerMethods:function(n){var i=u(n.actions,function(t){return e(t)}),r=this;o(c(n),function(e){if(!s(i,e)){var o=n[e];n[e]=function(){return r.trackSpy(n[e],arguments),o.apply(n,arguments)},t(n[e])}},this),this.listeners.push(n)},trigger:function(t,n,e){this.shadowDispatcher.trigger(t,n,e)},trackSpy:function(t,n){t.callCount+=1,t.called=!0,t.calls.push({args:p(n)})},hasAction:function(t,i){var r=!1;if(t.actions.forEach(function(t){e(t)===e(i)&&(r=!0)}),!r)return!1;var s=n(i),o=t[s.method],a=t.actionEventName(s.name),c=o.callCount;return t.dispatcher.trigger(a),o.callCount>c},off:function(){}}),i}(),JSKit.Controller=function(){function t(t,n){if(!t)throw new Error(this.className+": dispatcher is undefined");u(this,n,this),this.dispatcher=t,a.apply(this),o.call(this),this.actions.unshift("all"),s.call(this),this.initialize()}function n(t){if(t=t||"",t.match(/_|-|\s/)){var n=map(t.split(/_|-|\s/g),function(t,n){return n>0?t.charAt(0).toUpperCase()+t.slice(1):t.toLowerCase()}).join("");t=n}else t=t.toString();return t.charAt(0).toUpperCase()+t.slice(1)}function e(t){return t=t||"",t.replace(/([A-Z])/g," $1").replace(/^\s?/,"").replace(/-|\s/g,"_").toLowerCase()}function i(t){if(!f(this[t.method]))throw new Error(this.className+' action "'+t.name+this.eventSeparator+t.method+'" method is undefined')}function r(t){var n=m(t),e=n?p(d(t)):t,i=n?p(v(t)):t;return{name:i,method:e}}function s(){l(this.actions,function(t){var n=r(t);i.call(this,n),this.dispatcher.on(this.actionEventName(n.name),this[n.method],this)},this)}function o(){this.name=this.name||"Anonymous",h(this,{eventSeparator:":",actions:[],channel:"controller",className:n(this.name)+"Controller",controllerEventName:e(this.name)})}var a=_.bindAll,c=_.compact,h=_.defaults,l=_.each,u=_.assign,p=_.first,f=(_.functions,_.isFunction),m=_.isObject,v=_.keys,d=(_.uniq,_.values);return u(t.prototype,{initialize:function(){},all:function(){},actionEventName:function(t){return c([this.namespace,this.channel,this.controllerEventName,t]).join(this.eventSeparator)}}),t}(),JSKit.Application=function(){function t(){this.Controllers={},this.Dispatcher=new JSKit.Dispatcher}function n(t){if(t=t||"",t.match(/_|-|\s/)){var n=i(t.split(/_|-|\s/g),function(t,n){return n>0?t.charAt(0).toUpperCase()+t.slice(1):t.toLowerCase()}).join("");t=n}else t=t.toString();return t.charAt(0).toUpperCase()+t.slice(1)}var e=(_.clone,_.assign),i=(_.first,_.map);return t.prototype.createController=function(t,i){function r(){JSKit.Controller.apply(this,arguments)}var s=i.dispatcher||this.Dispatcher;return i.dispatcher&&delete i.dispatcher,t=n(t),e(i,{name:t}),e(r.prototype,JSKit.Controller.prototype,i),this[i.name+"Controller"]=r,this.Controllers[t]=new r(s,i),this.Controllers[t]},t}(),JSKit.createApplication=function(){return new JSKit.Application};
|