-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_index.co
More file actions
69 lines (56 loc) · 1.44 KB
/
Copy path_index.co
File metadata and controls
69 lines (56 loc) · 1.44 KB
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
{$} = Backbone
_ = (->@)!_ || require? 'underscore'
$J = Backbone.Joint = {$, _}
extend = Backbone.Model.extend
$J.assert = \
if console?
(cond, msg = 'Assertion failed')~>
console.warn msg if !cond
if cond then false else msg
else
(cond, msg = 'Assertion failed')~>
if cond then false else msg
$J.advice = \
if console?
(cond, msg)~>
console.info msg if !cond
if cond then false else msg
else
(cond, msg = 'Assertion failed')~>
if cond then false else msg
$J.before = (func, ...beforeFuncs)->
->
state =
context: @
args: @@
_.some beforeFuncs, (bfunc)->
bfunc.state ?= []
bfunc.state.unshift @
bfunc.apply @context, @args
@{args, context, breaked, preventDefault, returnValue} = bfunc.state.0
bfunc.state.shift!
@breaked
, state
if state.preventDefault
state.returnValue
else
func.apply state.context, state.args
$J.after = (func, ...afterFuncs)->
->
state =
context: @
args: @@
returnValue: func ...
_.some afterFuncs, (afunc)->
afunc.state ?= []
afunc.state.unshift @
afunc.apply @context, @args
@{args, context, breaked, returnValue} = afunc.state.0
afunc.state.shift!
@breaked
, state
state.returnValue
let @ = $J.Emitter = (->)
@extend = extend
@:: <<< Backbone.Events
@ <<< Backbone.Events