Skip to content

Commit f0bf1d3

Browse files
committed
Merge pull request #10 from coshx/fix/issues_in_event_firing_in_js
Fixes multiple issues when firing events
2 parents 4a07e08 + 1520357 commit f0bf1d3

File tree

14 files changed

+67
-53
lines changed

14 files changed

+67
-53
lines changed

Caravel.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Pod::Spec.new do |s|
1515
# summary should be tweet-length, and the description more in depth.
1616
#
1717

18-
version = "0.4.1"
18+
version = "0.4.2"
1919

2020
s.name = "Caravel"
2121
s.version = version

caravel-test.xcodeproj/project.pbxproj

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
A7C869061B18CEF30070AF5A /* basic_triggering.html in Resources */ = {isa = PBXBuildFile; fileRef = A7C869051B18CEF30070AF5A /* basic_triggering.html */; };
3030
A7C869081B18CF450070AF5A /* basic_triggering.js in Resources */ = {isa = PBXBuildFile; fileRef = A7C869071B18CF450070AF5A /* basic_triggering.js */; };
3131
A7DC081B1B18C73500D98DA5 /* BasicTriggeringController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7DC081A1B18C73500D98DA5 /* BasicTriggeringController.swift */; };
32+
A7EE0BA71BEC423E00D0925C /* Caravel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7EE0BA61BEC423E00D0925C /* Caravel.framework */; };
33+
A7EE0BA81BEC423E00D0925C /* Caravel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A7EE0BA61BEC423E00D0925C /* Caravel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3234
A7F1DE291B18045C001E9B94 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DE281B18045C001E9B94 /* AppDelegate.swift */; };
3335
A7F1DE2B1B18045C001E9B94 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DE2A1B18045C001E9B94 /* ViewController.swift */; };
3436
A7F1DE2E1B18045C001E9B94 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A7F1DE2C1B18045C001E9B94 /* Main.storyboard */; };
3537
A7F1DE301B18045C001E9B94 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A7F1DE2F1B18045C001E9B94 /* Images.xcassets */; };
3638
A7F1DE331B18045C001E9B94 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A7F1DE311B18045C001E9B94 /* LaunchScreen.xib */; };
3739
A7F1DE3F1B18045C001E9B94 /* caravel_testTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DE3E1B18045C001E9B94 /* caravel_testTests.swift */; };
38-
A7F1DE4B1B18067F001E9B94 /* Caravel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7F1DE4A1B18067F001E9B94 /* Caravel.framework */; };
3940
/* End PBXBuildFile section */
4041

4142
/* Begin PBXContainerItemProxy section */
@@ -48,6 +49,20 @@
4849
};
4950
/* End PBXContainerItemProxy section */
5051

52+
/* Begin PBXCopyFilesBuildPhase section */
53+
A7EE0BA91BEC423E00D0925C /* Embed Frameworks */ = {
54+
isa = PBXCopyFilesBuildPhase;
55+
buildActionMask = 2147483647;
56+
dstPath = "";
57+
dstSubfolderSpec = 10;
58+
files = (
59+
A7EE0BA81BEC423E00D0925C /* Caravel.framework in Embed Frameworks */,
60+
);
61+
name = "Embed Frameworks";
62+
runOnlyForDeploymentPostprocessing = 0;
63+
};
64+
/* End PBXCopyFilesBuildPhase section */
65+
5166
/* Begin PBXFileReference section */
5267
A75AD3F41B1913B600404C06 /* InitializationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InitializationController.swift; sourceTree = "<group>"; };
5368
A75AD3F61B1914FA00404C06 /* initialization.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = initialization.js; path = js/initialization.js; sourceTree = "<group>"; };
@@ -71,6 +86,7 @@
7186
A7C869051B18CEF30070AF5A /* basic_triggering.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = basic_triggering.html; path = html/basic_triggering.html; sourceTree = "<group>"; };
7287
A7C869071B18CF450070AF5A /* basic_triggering.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = basic_triggering.js; path = js/basic_triggering.js; sourceTree = "<group>"; };
7388
A7DC081A1B18C73500D98DA5 /* BasicTriggeringController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicTriggeringController.swift; sourceTree = "<group>"; };
89+
A7EE0BA61BEC423E00D0925C /* Caravel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Caravel.framework; path = "/Users/acadet/Library/Developer/Xcode/DerivedData/caravel-gxizvdjjntycpgaiopgmjthvbutx/Build/Products/Debug-iphoneos/Caravel.framework"; sourceTree = "<absolute>"; };
7490
A7F1DE231B18045C001E9B94 /* caravel-test.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "caravel-test.app"; sourceTree = BUILT_PRODUCTS_DIR; };
7591
A7F1DE271B18045C001E9B94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7692
A7F1DE281B18045C001E9B94 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -81,15 +97,14 @@
8197
A7F1DE381B18045C001E9B94 /* caravel-testTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "caravel-testTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
8298
A7F1DE3D1B18045C001E9B94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8399
A7F1DE3E1B18045C001E9B94 /* caravel_testTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = caravel_testTests.swift; sourceTree = "<group>"; };
84-
A7F1DE4A1B18067F001E9B94 /* Caravel.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Caravel.framework; path = "../build/Debug-iphoneos/Caravel.framework"; sourceTree = "<group>"; };
85100
/* End PBXFileReference section */
86101

87102
/* Begin PBXFrameworksBuildPhase section */
88103
A7F1DE201B18045C001E9B94 /* Frameworks */ = {
89104
isa = PBXFrameworksBuildPhase;
90105
buildActionMask = 2147483647;
91106
files = (
92-
A7F1DE4B1B18067F001E9B94 /* Caravel.framework in Frameworks */,
107+
A7EE0BA71BEC423E00D0925C /* Caravel.framework in Frameworks */,
93108
);
94109
runOnlyForDeploymentPostprocessing = 0;
95110
};
@@ -135,7 +150,7 @@
135150
A7F1DE1A1B18045C001E9B94 = {
136151
isa = PBXGroup;
137152
children = (
138-
A7F1DE4A1B18067F001E9B94 /* Caravel.framework */,
153+
A7EE0BA61BEC423E00D0925C /* Caravel.framework */,
139154
A7F1DE251B18045C001E9B94 /* caravel-test */,
140155
A7F1DE3B1B18045C001E9B94 /* caravel-testTests */,
141156
A7F1DE241B18045C001E9B94 /* Products */,
@@ -208,6 +223,7 @@
208223
A7F1DE1F1B18045C001E9B94 /* Sources */,
209224
A7F1DE201B18045C001E9B94 /* Frameworks */,
210225
A7F1DE211B18045C001E9B94 /* Resources */,
226+
A7EE0BA91BEC423E00D0925C /* Embed Frameworks */,
211227
);
212228
buildRules = (
213229
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Caravel.getDefault().register("From iOS", function(name, data) {
2-
$('body').append('<p>Received From iOS!</p>');
2+
$('body').append('<p class="js">Received From iOS!</p>');
33
});
44

55
Caravel.getDefault().post("From JS");

caravel-test/js/event_data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function ok(name) {
2-
$('body').append('<p>' + name + ' ok</p>');
2+
$('body').append('<p class="js">' + name + ' ok</p>');
33
}
44

55
function fail(name, data) {
66
if ((data instanceof Array) || (data instanceof Object)) {
77
data = JSON.stringify(data);
88
}
9-
$('body').append('<p>Failed for ' + name + ': received ' + data + '</p>');
9+
$('body').append('<p class="js">Failed for ' + name + ': received ' + data + '</p>');
1010
}
1111

1212
Caravel.getDefault().register("Bool", function(name, data) {

caravel-test/js/event_name.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Caravel.getDefault().register("Foo", function(name, data) {
22
if (name == "Foo") {
3-
$('body').append('<p>You should see me</p>');
3+
$('body').append('<p class="js">You should see me</p>');
44
} else {
5-
$('body').append('<p>You should not see me</p>');
5+
$('body').append('<p class="js">You should not see me</p>');
66
}
77
});
88

99
Caravel.getDefault().register("Foobar", function(name, data) {
10-
$('body').append('<p>You should not see me</p>');
10+
$('body').append('<p class="js">You should not see me</p>');
1111
});
1212

1313
Caravel.getDefault().post('Bar');

caravel-test/js/initialization.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Caravel.getDefault().register("Before", function(name, data) {
2-
$('body').append('<p>Before</p>');
2+
$('body').append('<p class="js">Before</p>');
33
});
44

55
Caravel.getDefault().register("After", function(name, data) {
6-
$('body').append('<p>After</p>');
6+
$('body').append('<p class="js">After</p>');
77
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Caravel.getDefault().register("AnEvent", function(name, data) {
2-
$('body').append('<p>First!</p>');
2+
$('body').append('<p class="js">First!</p>');
33
});
44

55
Caravel.getDefault().register("AnEvent", function(name, data) {
6-
$('body').append('<p>Second!</p>');
6+
$('body').append('<p class="js">Second!</p>');
77
});

caravel-test/js/two_buses.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Caravel.get("BarBus").register("AnEvent", function(name, data) {
2-
$('body').append('<p>You should see me first and only once</p>');
2+
$('body').append('<p class="js">You should see me first and only once</p>');
33
});
44

55
Caravel.get("FooBus").register("AnEvent", function(name, data) {
6-
$('body').append('<p>You should see me after and only once</p>');
6+
$('body').append('<p class="js">You should see me after and only once</p>');
77
});

caravel-test/js/two_events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Caravel.getDefault().register("ThirdEvent", function(name, data) {
2-
$('body').append('<p>You should see me and only me</p>');
2+
$('body').append('<p class="js">You should see me and only me</p>');
33
});
44

55
Caravel.getDefault().register("FourthEvent", function(name, data) {
6-
$('body').append('<p>You should not see me</p>');
6+
$('body').append('<p class="js">You should not see me</p>');
77
});
88

99
Caravel.getDefault().post("FirstEvent");

caravel/Caravel.swift

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class Caravel: NSObject, UIWebViewDelegate {
3030
*/
3131
private lazy var subscribers: [Subscriber] = [Subscriber]()
3232

33-
3433
/**
3534
* Denotes if the bus has received the init event from JS
3635
*/
@@ -99,6 +98,7 @@ public class Caravel: NSObject, UIWebViewDelegate {
9998
// has been raised (aka wait for JS before calling whenReady)
10099
self.isInitialized = false
101100
self.webView = webView
101+
self.subscribers = []
102102
UIWebViewDelegateMediator.subscribe(self.webView, subscriber: self)
103103
}
104104

@@ -131,24 +131,20 @@ public class Caravel: NSObject, UIWebViewDelegate {
131131
if self.secretName == args.busName {
132132
if args.eventName == "CaravelInit" { // Reserved event name. Triggers whenReady
133133
if !self.isInitialized {
134-
self.synchronized {
135-
if !self.isInitialized {
136-
self.isInitialized = true
134+
self.isInitialized = true
135+
136+
for i in self.initializers {
137+
let index = self.onGoingInitializersId
138+
139+
self.onGoingInitializers[index] = i
140+
self.onGoingInitializersId++
137141

138-
for i in self.initializers {
139-
let index = self.onGoingInitializersId
140-
141-
self.onGoingInitializers[index] = i
142-
self.onGoingInitializersId++
143-
144-
dispatch_async(dispatch_get_main_queue()) {
145-
i(self)
146-
self.onGoingInitializers.removeValueForKey(index)
147-
}
148-
}
149-
self.initializers = Array<(Caravel) -> Void>()
142+
dispatch_async(dispatch_get_main_queue()) {
143+
i(self)
144+
self.onGoingInitializers.removeValueForKey(index)
150145
}
151146
}
147+
self.initializers = Array<(Caravel) -> Void>()
152148
}
153149
} else {
154150
var eventData: AnyObject? = nil
@@ -187,7 +183,7 @@ public class Caravel: NSObject, UIWebViewDelegate {
187183
}
188184
} else {
189185
self.synchronized {
190-
if self.self.isInitialized {
186+
if self.isInitialized {
191187
dispatch_async(dispatch_get_main_queue()) {
192188
callback(self)
193189
}

0 commit comments

Comments
 (0)