joosy 1.1.0.alpha.1 → 1.1.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock
CHANGED
@@ -11,9 +11,8 @@ GIT
|
|
11
11
|
PATH
|
12
12
|
remote: .
|
13
13
|
specs:
|
14
|
-
joosy (1.1.0.alpha.
|
14
|
+
joosy (1.1.0.alpha.2)
|
15
15
|
haml_coffee_assets
|
16
|
-
i18n-js
|
17
16
|
sprockets
|
18
17
|
|
19
18
|
GEM
|
@@ -71,8 +70,6 @@ GEM
|
|
71
70
|
tilt (>= 1.3.3)
|
72
71
|
hike (1.2.1)
|
73
72
|
i18n (0.6.1)
|
74
|
-
i18n-js (2.1.2)
|
75
|
-
i18n
|
76
73
|
jasmine-core (1.3.1)
|
77
74
|
journey (1.0.4)
|
78
75
|
jquery-rails (2.2.0)
|
@@ -12,36 +12,42 @@ Joosy.Modules.Events =
|
|
12
12
|
# @param [Function] callback Action to run when all events were triggered at least once
|
13
13
|
# @param [Hash] options Options
|
14
14
|
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
wait: (name, events, callback) ->
|
16
|
+
@__oneShotEvents ||= Object.extended()
|
17
|
+
|
18
|
+
# unnamed binding
|
19
|
+
if Object.isFunction(events)
|
20
|
+
callback = events
|
21
|
+
events = name
|
22
|
+
name = @__oneShotEvents.keys().length.toString()
|
23
|
+
|
19
24
|
events = @__splitEvents events
|
20
25
|
@__validateEvents events
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
@__oneShotEvents ||= []
|
25
|
-
@__oneShotEvents.push [events, callback]
|
27
|
+
@__oneShotEvents[name] = [events, callback]
|
28
|
+
name
|
26
29
|
|
27
30
|
#
|
28
|
-
# Binds action to run each time any of given
|
31
|
+
# Binds action to run each time any of given event was triggered
|
29
32
|
#
|
30
33
|
# @param [String|Array] events List of events separated by space
|
31
34
|
# @param [Function] callback Action to run on trigger
|
32
35
|
# @param [Hash] options Options
|
33
36
|
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
bind: (name, events, callback) ->
|
38
|
+
@__boundEvents ||= Object.extended()
|
39
|
+
|
40
|
+
# unnamed binding
|
41
|
+
if Object.isFunction(events)
|
42
|
+
callback = events
|
43
|
+
events = name
|
44
|
+
name = @__boundEvents.keys().length.toString()
|
45
|
+
|
38
46
|
events = @__splitEvents events
|
39
47
|
@__validateEvents events
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
@__boundEvents ||= []
|
44
|
-
@__boundEvents.push [events, callback]
|
49
|
+
@__boundEvents[name] = [events, callback]
|
50
|
+
name
|
45
51
|
|
46
52
|
#
|
47
53
|
# Unbinds action from runing on trigger
|
@@ -49,10 +55,14 @@ Joosy.Modules.Events =
|
|
49
55
|
# @param [Function] target Action to unbind
|
50
56
|
#
|
51
57
|
unbind: (target) ->
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
needle = undefined
|
59
|
+
|
60
|
+
for name, [events, callback] of @__boundEvents
|
61
|
+
if (Object.isFunction(target) && callback == target) || name == target
|
62
|
+
needle = name
|
63
|
+
break
|
64
|
+
|
65
|
+
delete @__boundEvents[needle] if needle?
|
56
66
|
|
57
67
|
#
|
58
68
|
# Triggers event for {bind} and {wait}
|
@@ -63,16 +73,16 @@ Joosy.Modules.Events =
|
|
63
73
|
Joosy.Modules.Log.debugAs @, "Event #{event} triggered"
|
64
74
|
if @__oneShotEvents
|
65
75
|
fire = []
|
66
|
-
for [events, callback]
|
76
|
+
for name, [events, callback] of @__oneShotEvents
|
67
77
|
events.remove event
|
68
78
|
if events.length == 0
|
69
|
-
fire.push
|
70
|
-
fire.each (
|
71
|
-
callback = @__oneShotEvents[
|
72
|
-
@__oneShotEvents
|
79
|
+
fire.push name
|
80
|
+
fire.each (name) =>
|
81
|
+
callback = @__oneShotEvents[name][1]
|
82
|
+
delete @__oneShotEvents[name]
|
73
83
|
callback data...
|
74
84
|
if @__boundEvents
|
75
|
-
for [events, callback]
|
85
|
+
for name, [events, callback] of @__boundEvents
|
76
86
|
if events.any event
|
77
87
|
callback data...
|
78
88
|
|
@@ -89,7 +99,7 @@ Joosy.Modules.Events =
|
|
89
99
|
# @param [Function] block Configuration block (see example)
|
90
100
|
#
|
91
101
|
synchronize: (block) ->
|
92
|
-
context = new Joosy.
|
102
|
+
context = new Joosy.Events.SynchronizationContext(this)
|
93
103
|
block.call(this, context)
|
94
104
|
|
95
105
|
if context.expectations.length == 0
|
@@ -113,27 +123,25 @@ Joosy.Modules.Events =
|
|
113
123
|
unless Object.isArray(events) && events.length > 0
|
114
124
|
throw new Error "#{Joosy.Module.__className @}> bind invalid events: #{events}"
|
115
125
|
|
116
|
-
__isBound: (events, callback, oneShot = false) ->
|
117
|
-
haystack = if oneShot
|
118
|
-
@__oneShotEvents
|
119
|
-
else
|
120
|
-
@__boundEvents
|
121
126
|
|
122
|
-
|
127
|
+
Joosy.Events = {}
|
128
|
+
|
129
|
+
class Joosy.Events.Namespace
|
130
|
+
constructor: (@parent) ->
|
123
131
|
|
124
|
-
|
125
|
-
item[0].length == events.length &&
|
126
|
-
item[0].subtract(events).isEmpty() &&
|
127
|
-
item[1] == callback
|
132
|
+
bindings: []
|
128
133
|
|
129
|
-
|
134
|
+
bind: (args...) -> @bindings.push @parent.bind(args...)
|
135
|
+
unbind: ->
|
136
|
+
@parent.unbind b for b in @bindings
|
137
|
+
@bindings = []
|
130
138
|
|
131
139
|
#
|
132
140
|
# Internal representation of {Joosy.Modules.Events.synchronize} context
|
133
141
|
#
|
134
142
|
# @see Joosy.Modules.Events.synchronize
|
135
143
|
#
|
136
|
-
class Joosy.
|
144
|
+
class Joosy.Events.SynchronizationContext
|
137
145
|
@uid = 0
|
138
146
|
|
139
147
|
constructor: (@parent) ->
|
data/lib/joosy/version.rb
CHANGED
@@ -65,19 +65,6 @@ describe "Joosy.Modules.Events", ->
|
|
65
65
|
@box.wait 'event', callback
|
66
66
|
expect(@box.__oneShotEvents).toEqual [[['event'], callback], [['event'], callback], [['event'], callback]]
|
67
67
|
|
68
|
-
it "should ignore multiple binding", ->
|
69
|
-
callback = ->
|
70
|
-
|
71
|
-
@box.bind 'event', callback
|
72
|
-
3.times =>
|
73
|
-
@box.bind 'event', callback, unique: true
|
74
|
-
expect(@box.__boundEvents).toEqual [[['event'], callback]]
|
75
|
-
|
76
|
-
@box.wait 'event', callback
|
77
|
-
3.times =>
|
78
|
-
@box.wait 'event', callback, unique: true
|
79
|
-
expect(@box.__oneShotEvents).toEqual [[['event'], callback]]
|
80
|
-
|
81
68
|
it "should handle inheritance well", ->
|
82
69
|
callback = sinon.spy()
|
83
70
|
@sub.wait 'foo', callback
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joosy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.alpha.
|
4
|
+
version: 1.1.0.alpha.2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,11 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-01
|
15
|
+
date: 2013-02-01 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: sprockets
|
19
|
-
requirement: &
|
19
|
+
requirement: &70336034677120 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
22
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: '0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *70336034677120
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: haml_coffee_assets
|
30
|
-
requirement: &
|
30
|
+
requirement: &70336034676020 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
version: '0'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *70336034676020
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: jquery-rails
|
41
|
-
requirement: &
|
41
|
+
requirement: &70336034674640 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ! '>='
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: '0'
|
47
47
|
type: :development
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *70336034674640
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: guard
|
52
|
-
requirement: &
|
52
|
+
requirement: &70336034673840 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ! '>='
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
version: '0'
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
|
-
version_requirements: *
|
60
|
+
version_requirements: *70336034673840
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: guard-coffeescript
|
63
|
-
requirement: &
|
63
|
+
requirement: &70336034672920 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
66
|
- - ! '>='
|
@@ -68,10 +68,10 @@ dependencies:
|
|
68
68
|
version: '0'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
|
-
version_requirements: *
|
71
|
+
version_requirements: *70336034672920
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: guard-sprockets
|
74
|
-
requirement: &
|
74
|
+
requirement: &70336034671560 !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
77
77
|
- - ! '>='
|
@@ -79,10 +79,10 @@ dependencies:
|
|
79
79
|
version: '0'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
|
-
version_requirements: *
|
82
|
+
version_requirements: *70336034671560
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: jasmine
|
85
|
-
requirement: &
|
85
|
+
requirement: &70336034670000 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ! '>='
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
|
-
version_requirements: *
|
93
|
+
version_requirements: *70336034670000
|
94
94
|
description: A gem wrapper to include Joosy via the asset pipeline.
|
95
95
|
email: boris@roundlake.ru
|
96
96
|
executables: []
|