turbo_boost-streams 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,26 +15,36 @@ function withInvokeEvents (receiver, detail, callback) {
15
15
 
16
16
  target.dispatchEvent(new CustomEvent(invokeEvents.before, options))
17
17
 
18
- const result = callback(object)
19
- options.detail.result = result
20
- target.dispatchEvent(new CustomEvent(invokeEvents.after, options))
21
-
22
- let promise
23
- if (result instanceof Animation) promise = result.finished
24
- if (result instanceof Promise) promise = result
25
-
26
- if (promise)
27
- promise.then(
28
- () => {
29
- options.detail.promise = 'fulfilled'
30
- target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
31
- },
32
- () => {
33
- options.detail.promise = 'rejected'
34
- target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
35
- }
36
- )
37
- else target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
18
+ // the before event can provide invoke instructions my modifying the event detail
19
+ // For example, { delay: 1000 } will delay the invocation by 1000ms
20
+ let { delay } = detail.invoke || {}
21
+ delay = delay || 0
22
+
23
+ const execute = () => {
24
+ const result = callback(object)
25
+ options.detail.result = result
26
+ target.dispatchEvent(new CustomEvent(invokeEvents.after, options))
27
+
28
+ let promise
29
+ if (result instanceof Animation) promise = result.finished
30
+ if (result instanceof Promise) promise = result
31
+
32
+ if (promise)
33
+ promise.then(
34
+ () => {
35
+ options.detail.promise = 'fulfilled'
36
+ target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
37
+ },
38
+ () => {
39
+ options.detail.promise = 'rejected'
40
+ target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
41
+ }
42
+ )
43
+ else target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
44
+ }
45
+
46
+ if (delay > 0) setTimeout(execute, delay)
47
+ else execute()
38
48
  }
39
49
 
40
50
  function invokeDispatchEvent (method, args, receivers) {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TurboBoost
4
4
  module Streams
5
- VERSION = "0.0.7"
5
+ VERSION = "0.0.8"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_boost-streams
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Hopkins (hopsoft)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
11
+ date: 2023-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails