forked from regularjs/regular-state
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestate.pack.js
1763 lines (1376 loc) · 45.3 KB
/
restate.pack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("Regular"));
else if(typeof define === 'function' && define.amd)
define(["Regular"], factory);
else if(typeof exports === 'object')
exports["restate"] = factory(require("Regular"));
else
root["restate"] = factory(root["Regular"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
var Regular = __webpack_require__(2);
var Stateman = __webpack_require__(3);
var _ = __webpack_require__(11);
var dom =Regular.dom;
var createRestate = __webpack_require__(12);
var Restate = createRestate( Stateman );
var so = Restate.prototype;
var oldStateFn = so.state;
var oldStart = so.start;
so.start = function(options, callback){
var self = this;
options = options || {};
var ssr = options.ssr;
var view = options.view;
this.view = view;
// prevent default stateman autoLink feature
options.autolink = false;
if(ssr) {
// wont fix .
options.autofix = false;
options.html5 = true;
}
// delete unused options of stateman
delete options.ssr;
delete options.view;
if( options.html5 && window.history && "onpopstate" in window ){
this.ssr = ssr;
// dom.on( document.body, "click", function(ev){
// var target = ev.target, href;
// if(target.getAttribute('data-autolink') != null){
// ev.preventDefault();
// href = dom.attr(target, 'href');
// self.nav(href);
// }
// });
}
oldStart.call(this, options, callback)
return this;
}
so.state = function(name, config){
var manager = this;
var oldConfig;
if( typeof name === 'string'){
if(!config) return oldStateFn.call(this, name)
oldConfig = config;
// 不代理canEnter事件, 因为此时component还不存在
// mount (if not installed, install first)
// 1. .Null => a.b.c
// canEnter a -> canEnter a.b -> canEnter a.b.c ->
// -> install a ->enter a -> mount a
// -> install a.b -> enter a.b -> mount a.b
// -> install a.b.c -> enter a.b.c -> mount a.b.c
// 2. update a.b.c
// -> install a -> mount a
// -> install a.b -> mount a.b
// -> install a.b.c -> mount a.b.c
// 3. a.b.c -> a.b.d
// canLeave c -> canEnter d -> leave c
// -> install a -> mount a ->
// -> install b -> mount b ->
// -> install d -> enter d -> mount d
function install( option , isEnter){
var component = this.component;
var parent = this.parent;
var self = this;
var ssr = option.ssr = isEnter && option.firstTime && manager.ssr && this.ssr !== false;
if(component && component.$phase === 'destroyed' ){
component = null;
}
var installOption = {
ssr: ssr,
state: this,
param: option.param,
component: component,
originOption: option
}
var installPromise = manager.install( installOption ).then( function( installed ){
var globalView = manager.view, view, ret;
var Component = installed.Component;
var needComponent = !component || component.constructor !== Component;
if(parent.component){
view = parent.component.$viewport;
}else{
view = globalView;
}
// if(!view) throw Error('need viewport for ' + self.name );
if( needComponent ){
// 这里需要给出提示
if(component) component.destroy();
var mountNode = ssr && view;
component = self.component = new Component({
mountNode: mountNode,
data: _.extend({}, installed.data),
$state: manager
})
}else{
_.extend( component.data, installed.data, true)
}
if( (needComponent && !mountNode) || (!needComponent && isEnter) ) component.$inject(view);
return component;
})
if(isEnter){
installPromise = installPromise.then(function(){
return _.proxyMethod(self.component, 'enter', option)
})
}
return installPromise.then( self.mount.bind( self, option ) ).then(function(){
self.component.$update(function(){
self.component.$mute(false)
});
})
}
config = {
component: null,
install: install,
mount: function( option ){
return _.proxyMethod(this.component, 'mount', option)
},
canEnter: function(option){
return _.proxyMethod(this, oldConfig.canEnter, option )
},
canLeave: function(option){
return _.proxyMethod(this.component, 'canLeave', option)
},
update: function(option){
return this.install(option, false);
},
enter: function(option){
return this.install(option, true);
},
leave: function( option ){
var component = this.component;
if(!component) return;
return Promise.resolve().then(function(){
return _.proxyMethod(component, 'leave', option)
}).then(function(){
component.$inject(false);
component.$mute(true);
})
}
}
_.extend(config, oldConfig, true)
}
return oldStateFn.call(this, name, config)
}
module.exports = Restate;
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
var stateman;
if( typeof window === 'object' ){
stateman = __webpack_require__(4);
stateman.History = __webpack_require__(7);
stateman.util = __webpack_require__(6);
stateman.isServer = false;
}else{
stateman = __webpack_require__(10);
stateman.isServer = true;
}
stateman.State = __webpack_require__(5);
module.exports = stateman;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
var State = __webpack_require__(5),
History = __webpack_require__(7),
Base = __webpack_require__(9),
_ = __webpack_require__(6),
baseTitle = document.title,
stateFn = State.prototype.state;
function StateMan(options){
if(this instanceof StateMan === false){ return new StateMan(options); }
options = options || {};
Base.call(this, options);
if(options.history) this.history = options.history;
this._stashCallback = [];
this.current = this.active = this;
// auto update document.title, when navigation has been down
this.on("end", function( options ){
var cur = this.current;
document.title = cur.getTitle( options ) || baseTitle ;
});
}
var o =_.inherit( StateMan, Base.prototype );
_.extend(o , {
start: function(options, callback){
this._startCallback = callback;
if( !this.history ) this.history = new History(options);
if( !this.history.isStart ){
this.history.on("change", _.bind(this._afterPathChange, this));
this.history.start();
}
return this;
},
stop: function(){
this.history.stop();
},
// @TODO direct go the point state
go: function(state, option, callback){
option = option || {};
var statename;
if(typeof state === "string") {
statename = state;
state = this.state(state);
}
if(!state) return this._notfound({state:statename});
if(typeof option === "function"){
callback = option;
option = {};
}
if(option.encode !== false){
var url = state.encode(option.param);
option.path = url;
this.nav(url, {silent: true, replace: option.replace});
}
this._go(state, option, callback);
return this;
},
nav: function(url, options, callback){
if(typeof options === "function"){
callback = options;
options = {};
}
options = options || {};
options.path = url;
this.history.nav( url, _.extend({silent: true}, options));
if(!options.silent) this._afterPathChange( _.cleanPath(url) , options , callback);
return this;
},
// after pathchange changed
// @TODO: afterPathChange need based on decode
_afterPathChange: function(path, options ,callback){
this.emit("history:change", path);
var found = this.decode(path);
options = options || {};
options.path = path;
if(!found){
return this._notfound(options);
}
options.param = found.param;
if( options.firstTime && !callback){
callback = this._startCallback;
delete this._startCallback;
}
this._go( found.state, options, callback );
},
_notfound: function(options){
return this.emit("notfound", options);
},
// goto the state with some option
_go: function(state, option, callback){
var over;
if(state.hasNext && this.strict) return this._notfound({name: state.name});
option.param = option.param || {};
var current = this.current,
baseState = this._findBase(current, state),
prepath = this.path,
self = this;
if( typeof callback === "function" ) this._stashCallback.push(callback);
// if we done the navigating when start
function done(success){
over = true;
if( success !== false ) self.emit("end", option);
self.pending = null;
self._popStash(option);
}
option.previous = current;
option.current = state;
if(current !== state){
option.stop = function(){
done(false);
self.nav( prepath? prepath: "/", {silent:true});
};
self.emit("begin", option);
}
// if we stop it in 'begin' listener
if(over === true) return;
option.phase = 'permission';
this._walk(current, state, option, true , _.bind( function( notRejected ){
if( notRejected===false ){
// if reject in callForPermission, we will return to old
prepath && this.nav( prepath, {silent: true});
done(false, 2);
return this.emit('abort', option);
}
// stop previous pending.
if(this.pending) this.pending.stop();
this.pending = option;
this.path = option.path;
this.current = option.current;
this.param = option.param;
this.previous = option.previous;
option.phase = 'navigation';
this._walk(current, state, option, false, _.bind(function( notRejected ){
if( notRejected === false ){
this.current = this.active;
done(false);
return this.emit('abort', option);
}
this.active = option.current;
option.phase = 'completion';
return done();
}, this) );
}, this) );
},
_popStash: function(option){
var stash = this._stashCallback, len = stash.length;
this._stashCallback = [];
if(!len) return;
for(var i = 0; i < len; i++){
stash[i].call(this, option);
}
},
// the transition logic Used in Both canLeave canEnter && leave enter LifeCycle
_walk: function(from, to, option, callForPermit , callback){
// if(from === to) return callback();
// nothing -> app.state
var parent = this._findBase(from , to);
var self = this;
option.backward = true;
this._transit( from, parent, option, callForPermit , function( notRejected ){
if( notRejected === false ) return callback( notRejected );
// only actual transiton need update base state;
option.backward = false;
self._walkUpdate(self, parent, option, callForPermit, function(notRejected){
if(notRejected === false) return callback(notRejected);
self._transit( parent, to, option, callForPermit, callback);
});
});
},
_transit: function(from, to, option, callForPermit, callback){
// touch the ending
if( from === to ) return callback();
var back = from.name.length > to.name.length;
var method = back? 'leave': 'enter';
var applied;
// use canEnter to detect permission
if( callForPermit) method = 'can' + method.replace(/^\w/, function(a){ return a.toUpperCase(); });
var loop = _.bind(function( notRejected ){
// stop transition or touch the end
if( applied === to || notRejected === false ) return callback(notRejected);
if( !applied ) {
applied = back? from : this._computeNext(from, to);
}else{
applied = this._computeNext(applied, to);
}
if( (back && applied === to) || !applied )return callback( notRejected );
this._moveOn( applied, method, option, loop );
}, this);
loop();
},
_moveOn: function( applied, method, option, callback){
var isDone = false;
var isPending = false;
option.async = function(){
isPending = true;
return done;
};
function done( notRejected ){
if( isDone ) return;
isPending = false;
isDone = true;
callback( notRejected );
}
option.stop = function(){
done( false );
};
this.active = applied;
var retValue = applied[method]? applied[method]( option ): true;
if(method === 'enter') applied.visited = true;
// promise
// need breadk , if we call option.stop first;
if( _.isPromise(retValue) ){
return this._wrapPromise(retValue, done);
}
// if haven't call option.async yet
if( !isPending ) done( retValue );
},
_wrapPromise: function( promise, next ){
return promise.then( next, function(err){
//TODO: 万一promise中throw了Error如何处理?
if(err instanceof Error) throw err;
next(false);
}) ;
},
_computeNext: function( from, to ){
var fname = from.name;
var tname = to.name;
var tsplit = tname.split('.');
var fsplit = fname.split('.');
var tlen = tsplit.length;
var flen = fsplit.length;
if(fname === '') flen = 0;
if(tname === '') tlen = 0;
if( flen < tlen ){
fsplit[flen] = tsplit[flen];
}else{
fsplit.pop();
}
return this.state(fsplit.join('.'));
},
_findQuery: function(querystr){
var queries = querystr && querystr.split("&"), query= {};
if(queries){
var len = queries.length;
for(var i =0; i< len; i++){
var tmp = queries[i].split("=");
query[tmp[0]] = tmp[1];
}
}
return query;
},
_sortState: function( a, b ){
return ( b.priority || 0 ) - ( a.priority || 0 );
},
// find the same branch;
_findBase: function(now, before){
if(!now || !before || now == this || before == this) return this;
var np = now, bp = before, tmp;
while(np && bp){
tmp = bp;
while(tmp){
if(np === tmp) return tmp;
tmp = tmp.parent;
}
np = np.parent;
}
},
// check the query and Param
_walkUpdate: function(baseState, to, options, callForPermit, done){
var method = callForPermit? 'canUpdate': 'update';
var from = baseState;
var self = this;
var pathes = [], node = to;
while(node !== this){
pathes.push( node );
node = node.parent;
}
var loop = function( notRejected ){
if( notRejected === false ) return done( false );
if( !pathes.length ) return done();
from = pathes.pop();
self._moveOn( from, method, options, loop )
}
self._moveOn( from, method, options, loop )
}
}, true);
module.exports = StateMan;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
var _ = __webpack_require__(6);
function State(option){
this._states = {};
this._pending = false;
this.visited = false;
if(option) this.config(option);
}
//regexp cache
State.rCache = {};
_.extend( _.emitable( State ), {
getTitle: function(options){
var cur = this ,title;
while( cur ){
title = cur.title;
if(title) return typeof title === 'function'? cur.title(options): cur.title
cur = cur.parent;
}
return title;
},
state: function(stateName, config){
if(_.typeOf(stateName) === "object"){
var keys = _.values(stateName, true);
keys.sort(function(ka, kb){
return _.countDot(ka) - _.countDot(kb);
});
for(var i = 0, len = keys.length; i< len ;i++){
var key = keys[i];
this.state(key, stateName[key])
}
return this;
}
var current = this, next, nextName, states = this._states, i=0;
if( typeof stateName === "string" ) stateName = stateName.split(".");
var slen = stateName.length;
var stack = [];
do{
nextName = stateName[i];
next = states[nextName];
stack.push(nextName);
if(!next){
if(!config) return;
next = states[nextName] = new State();
_.extend(next, {
parent: current,
manager: current.manager || current,
name: stack.join("."),
currentName: nextName
});
current.hasNext = true;
next.configUrl();
}
current = next;
states = next._states;
}while((++i) < slen )
if(config){
next.config(config);
return this;
} else {
return current;
}
},
config: function(configure){
configure = this._getConfig(configure);
for(var i in configure){
var prop = configure[i];
switch(i){
case "url":
if(typeof prop === "string"){
this.url = prop;
this.configUrl();
}
break;
case "events":
this.on(prop);
break;
default:
this[i] = prop;
}
}
},
// children override
_getConfig: function(configure){
return typeof configure === "function"? {enter: configure} : configure;
},
//from url
configUrl: function(){
var url = "" , base = this;
while( base ){
url = (typeof base.url === "string" ? base.url: (base.currentName || "")) + "/" + url;
// means absolute;
if(url.indexOf("^/") === 0) {
url = url.slice(1);
break;
}
base = base.parent;
}
this.pattern = _.cleanPath("/" + url);
var pathAndQuery = this.pattern.split("?");
this.pattern = pathAndQuery[0];
// some Query we need watched
_.extend(this, _.normalize(this.pattern), true);
},
encode: function(param){
var state = this;
param = param || {};
var matched = "%";
var url = state.matches.replace(/\(([\w-]+)\)/g, function(all, capture){
var sec = param[capture];
var stype = typeof sec;
if(stype === 'boolean' || stype === 'number') sec = ''+sec;
sec = sec || '';
matched+= capture + "%";
return sec;
}) + "?";
// remained is the query, we need concat them after url as query
for(var i in param) {
if( matched.indexOf("%"+i+"%") === -1) url += i + "=" + param[i] + "&";
}
return _.cleanPath( url.replace(/(?:\?|&)$/,"") );
},
decode: function( path ){
var matched = this.regexp.exec(path),
keys = this.keys;
if(matched){
var param = {};
for(var i =0,len=keys.length;i<len;i++){
param[keys[i]] = matched[i+1];
}
return param;
}else{
return false;
}
},
// by default, all lifecycle is permitted
async: function(){
throw new Error( 'please use option.async instead');
}
});
module.exports = State;
/***/ }),
/* 6 */
/***/ (function(module, exports) {
var _ = module.exports = {};
var slice = [].slice, o2str = ({}).toString;
// merge o2's properties to Object o1.
_.extend = function(o1, o2, override){
for(var i in o2) if(override || o1[i] === undefined){
o1[i] = o2[i];
}
return o1;
};
var rDot = /\./g;
_.countDot = function(word){
var ret = word.match(rDot)
return ret? ret.length: 0;
}
_.values = function( o, key){
var keys = [];
for(var i in o) if( o.hasOwnProperty(i) ){
keys.push( key? i: o[i] );
}
return keys;
};
_.inherit = function( cstor, o ){
function Faker(){}
Faker.prototype = o;
cstor.prototype = new Faker();
cstor.prototype.constructor = cstor;
return o;
}
_.slice = function(arr, index){
return slice.call(arr, index);
};
_.typeOf = function typeOf (o) {
return o == null ? String(o) : o2str.call(o).slice(8, -1).toLowerCase();
};
//strict eql
_.eql = function(o1, o2){
var t1 = _.typeOf(o1), t2 = _.typeOf(o2);
if( t1 !== t2) return false;
if(t1 === 'object'){
// only check the first's properties
for(var i in o1){
// Immediately return if a mismatch is found.
if( o1[i] !== o2[i] ) return false;
}
return true;
}
return o1 === o2;
};
// small emitter
_.emitable = (function(){
function norm(ev){
var eventAndNamespace = (ev||'').split(':');
return {event: eventAndNamespace[0], namespace: eventAndNamespace[1]};
}
var API = {
once: function(event, fn){
var callback = function(){
fn.apply(this, arguments);
this.off(event, callback);
};
return this.on(event, callback);
},
on: function(event, fn) {
if(typeof event === 'object'){
for (var i in event) {
this.on(i, event[i]);
}
return this;
}
var ne = norm(event);
event=ne.event;
if(event && typeof fn === 'function' ){
var handles = this._handles || (this._handles = {}),
calls = handles[event] || (handles[event] = []);
fn._ns = ne.namespace;
calls.push(fn);
}
return this;
},
off: function(event, fn) {
var ne = norm(event); event = ne.event;
if(!event || !this._handles) this._handles = {};
var handles = this._handles;
var calls = handles[event];
if (calls) {
if (!fn && !ne.namespace) {
handles[event] = [];
}else{
for (var i = 0, len = calls.length; i < len; i++) {
if ( (!fn || fn === calls[i]) && (!ne.namespace || calls[i]._ns === ne.namespace) ) {
calls.splice(i, 1);
return this;
}
}
}
}
return this;
},
emit: function(event){
var ne = norm(event); event = ne.event;
var args = _.slice(arguments, 1),
handles = this._handles, calls;
if (!handles || !(calls = handles[event])) return this;
for (var i = 0, len = calls.length; i < len; i++) {
var fn = calls[i];
if( !ne.namespace || fn._ns === ne.namespace ) fn.apply(this, args);
}
return this;
}
};
return function(obj){
obj = typeof obj == "function" ? obj.prototype : obj;
return _.extend(obj, API);
};
})();
_.bind = function(fn, context){
return function(){
return fn.apply(context, arguments);
};
};