Skip to content

Commit c090de8

Browse files
committed
Merge pull request #31 from coshx/zealous-hornet
Zealous hornet release
2 parents 134e303 + a92fe2f commit c090de8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1502
-691
lines changed

Caravel.podspec

Lines changed: 2 additions & 2 deletions
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.4"
18+
version = "1.0.0"
1919

2020
s.name = "Caravel"
2121
s.version = version
@@ -62,7 +62,7 @@ Pod::Spec.new do |s|
6262
#
6363

6464
# s.platform = :ios
65-
s.platform = :ios, "8.0"
65+
s.platform = :ios, "8.1"
6666

6767
# When using multiple platforms
6868
# s.ios.deployment_target = "5.0"

Caravel.xcodeproj/project.pbxproj

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
A7199EEA1BFC038D00757E4F /* CaravelError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EE91BFC038D00757E4F /* CaravelError.swift */; };
11+
A7199EEC1BFC0EC700757E4F /* CaravelFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EEB1BFC0EC700757E4F /* CaravelFactory.swift */; };
12+
A7199EEE1BFC11E000757E4F /* NSObjectExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EED1BFC11E000757E4F /* NSObjectExtension.swift */; };
13+
A7199EF01BFC134B00757E4F /* ThreadingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EEF1BFC134B00757E4F /* ThreadingHelper.swift */; };
14+
A7199EF31BFC1F4400757E4F /* EventBus.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7199EF21BFC1F4400757E4F /* EventBus.swift */; };
1015
A7AC9F281B3493EB0041EB0B /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7AC9F271B3493EB0041EB0B /* StringExtension.swift */; };
1116
A7F1DD981B17D957001E9B94 /* caravel.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F1DD971B17D957001E9B94 /* caravel.h */; settings = {ATTRIBUTES = (Public, ); }; };
1217
A7F1DD9E1B17D958001E9B94 /* Caravel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7F1DD921B17D957001E9B94 /* Caravel.framework */; };
1318
A7F1DDA51B17D958001E9B94 /* caravelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDA41B17D958001E9B94 /* caravelTests.swift */; };
1419
A7F1DDB21B17D989001E9B94 /* Caravel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDAE1B17D989001E9B94 /* Caravel.swift */; };
15-
A7F1DDB31B17D989001E9B94 /* Subscriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDAF1B17D989001E9B94 /* Subscriber.swift */; };
20+
A7F1DDB31B17D989001E9B94 /* EventSubscriber.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDAF1B17D989001E9B94 /* EventSubscriber.swift */; };
1621
A7F1DDB51B17D989001E9B94 /* UIWebViewDelegateMediator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */; };
1722
A7F1DDB81B17E5F8001E9B94 /* DataSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */; };
18-
A7F1DDBA1B17E6F5001E9B94 /* SupportedType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDB91B17E6F5001E9B94 /* SupportedType.swift */; };
1923
A7F1DDBC1B17EF24001E9B94 /* ArgumentParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */; };
2024
/* End PBXBuildFile section */
2125

@@ -30,6 +34,11 @@
3034
/* End PBXContainerItemProxy section */
3135

3236
/* Begin PBXFileReference section */
37+
A7199EE91BFC038D00757E4F /* CaravelError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaravelError.swift; sourceTree = "<group>"; };
38+
A7199EEB1BFC0EC700757E4F /* CaravelFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CaravelFactory.swift; path = internal/CaravelFactory.swift; sourceTree = "<group>"; };
39+
A7199EED1BFC11E000757E4F /* NSObjectExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSObjectExtension.swift; path = utils/NSObjectExtension.swift; sourceTree = "<group>"; };
40+
A7199EEF1BFC134B00757E4F /* ThreadingHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ThreadingHelper.swift; path = utils/ThreadingHelper.swift; sourceTree = "<group>"; };
41+
A7199EF21BFC1F4400757E4F /* EventBus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventBus.swift; sourceTree = "<group>"; };
3342
A7AC9F271B3493EB0041EB0B /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StringExtension.swift; path = utils/StringExtension.swift; sourceTree = "<group>"; };
3443
A7F1DD921B17D957001E9B94 /* Caravel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Caravel.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3544
A7F1DD961B17D957001E9B94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -38,11 +47,10 @@
3847
A7F1DDA31B17D958001E9B94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3948
A7F1DDA41B17D958001E9B94 /* caravelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = caravelTests.swift; sourceTree = "<group>"; };
4049
A7F1DDAE1B17D989001E9B94 /* Caravel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Caravel.swift; sourceTree = "<group>"; };
41-
A7F1DDAF1B17D989001E9B94 /* Subscriber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Subscriber.swift; sourceTree = "<group>"; };
42-
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIWebViewDelegateMediator.swift; sourceTree = "<group>"; };
43-
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSerializer.swift; sourceTree = "<group>"; };
44-
A7F1DDB91B17E6F5001E9B94 /* SupportedType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SupportedType.swift; sourceTree = "<group>"; };
45-
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArgumentParser.swift; sourceTree = "<group>"; };
50+
A7F1DDAF1B17D989001E9B94 /* EventSubscriber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EventSubscriber.swift; path = internal/EventSubscriber.swift; sourceTree = "<group>"; };
51+
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIWebViewDelegateMediator.swift; path = internal/UIWebViewDelegateMediator.swift; sourceTree = "<group>"; };
52+
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DataSerializer.swift; path = internal/DataSerializer.swift; sourceTree = "<group>"; };
53+
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArgumentParser.swift; path = internal/ArgumentParser.swift; sourceTree = "<group>"; };
4654
/* End PBXFileReference section */
4755

4856
/* Begin PBXFrameworksBuildPhase section */
@@ -64,10 +72,24 @@
6472
/* End PBXFrameworksBuildPhase section */
6573

6674
/* Begin PBXGroup section */
75+
A7199EF11BFC1EBE00757E4F /* internal */ = {
76+
isa = PBXGroup;
77+
children = (
78+
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */,
79+
A7199EEB1BFC0EC700757E4F /* CaravelFactory.swift */,
80+
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */,
81+
A7F1DDAF1B17D989001E9B94 /* EventSubscriber.swift */,
82+
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */,
83+
);
84+
name = internal;
85+
sourceTree = "<group>";
86+
};
6787
A7AC9F261B3493CA0041EB0B /* utils */ = {
6888
isa = PBXGroup;
6989
children = (
7090
A7AC9F271B3493EB0041EB0B /* StringExtension.swift */,
91+
A7199EED1BFC11E000757E4F /* NSObjectExtension.swift */,
92+
A7199EEF1BFC134B00757E4F /* ThreadingHelper.swift */,
7193
);
7294
name = utils;
7395
sourceTree = "<group>";
@@ -93,15 +115,13 @@
93115
A7F1DD941B17D957001E9B94 /* caravel */ = {
94116
isa = PBXGroup;
95117
children = (
96-
A7AC9F261B3493CA0041EB0B /* utils */,
97-
A7F1DDAE1B17D989001E9B94 /* Caravel.swift */,
98-
A7F1DDAF1B17D989001E9B94 /* Subscriber.swift */,
99-
A7F1DDB11B17D989001E9B94 /* UIWebViewDelegateMediator.swift */,
100118
A7F1DD971B17D957001E9B94 /* caravel.h */,
119+
A7F1DDAE1B17D989001E9B94 /* Caravel.swift */,
120+
A7199EE91BFC038D00757E4F /* CaravelError.swift */,
121+
A7199EF21BFC1F4400757E4F /* EventBus.swift */,
122+
A7199EF11BFC1EBE00757E4F /* internal */,
101123
A7F1DD951B17D957001E9B94 /* Supporting Files */,
102-
A7F1DDB71B17E5F8001E9B94 /* DataSerializer.swift */,
103-
A7F1DDB91B17E6F5001E9B94 /* SupportedType.swift */,
104-
A7F1DDBB1B17EF24001E9B94 /* ArgumentParser.swift */,
124+
A7AC9F261B3493CA0041EB0B /* utils */,
105125
);
106126
path = caravel;
107127
sourceTree = "<group>";
@@ -145,9 +165,9 @@
145165
/* End PBXHeadersBuildPhase section */
146166

147167
/* Begin PBXNativeTarget section */
148-
A7F1DD911B17D957001E9B94 /* Caravel.temp_caseinsensitive_rename */ = {
168+
A7F1DD911B17D957001E9B94 /* Caravel */ = {
149169
isa = PBXNativeTarget;
150-
buildConfigurationList = A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_rename" */;
170+
buildConfigurationList = A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel" */;
151171
buildPhases = (
152172
A7F1DD8D1B17D957001E9B94 /* Sources */,
153173
A7F1DD8E1B17D957001E9B94 /* Frameworks */,
@@ -158,14 +178,14 @@
158178
);
159179
dependencies = (
160180
);
161-
name = Caravel.temp_caseinsensitive_rename;
181+
name = Caravel;
162182
productName = caravel;
163183
productReference = A7F1DD921B17D957001E9B94 /* Caravel.framework */;
164184
productType = "com.apple.product-type.framework";
165185
};
166-
A7F1DD9C1B17D958001E9B94 /* Caravel.temp_caseinsensitive_renameTests */ = {
186+
A7F1DD9C1B17D958001E9B94 /* CaravelTests */ = {
167187
isa = PBXNativeTarget;
168-
buildConfigurationList = A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_renameTests" */;
188+
buildConfigurationList = A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "CaravelTests" */;
169189
buildPhases = (
170190
A7F1DD991B17D958001E9B94 /* Sources */,
171191
A7F1DD9A1B17D958001E9B94 /* Frameworks */,
@@ -176,7 +196,7 @@
176196
dependencies = (
177197
A7F1DDA01B17D958001E9B94 /* PBXTargetDependency */,
178198
);
179-
name = Caravel.temp_caseinsensitive_renameTests;
199+
name = CaravelTests;
180200
productName = caravelTests;
181201
productReference = A7F1DD9D1B17D958001E9B94 /* CaravelTests.xctest */;
182202
productType = "com.apple.product-type.bundle.unit-test";
@@ -212,8 +232,8 @@
212232
projectDirPath = "";
213233
projectRoot = "";
214234
targets = (
215-
A7F1DD911B17D957001E9B94 /* Caravel.temp_caseinsensitive_rename */,
216-
A7F1DD9C1B17D958001E9B94 /* Caravel.temp_caseinsensitive_renameTests */,
235+
A7F1DD911B17D957001E9B94 /* Caravel */,
236+
A7F1DD9C1B17D958001E9B94 /* CaravelTests */,
217237
);
218238
};
219239
/* End PBXProject section */
@@ -240,12 +260,16 @@
240260
isa = PBXSourcesBuildPhase;
241261
buildActionMask = 2147483647;
242262
files = (
243-
A7F1DDB31B17D989001E9B94 /* Subscriber.swift in Sources */,
263+
A7F1DDB31B17D989001E9B94 /* EventSubscriber.swift in Sources */,
264+
A7199EF31BFC1F4400757E4F /* EventBus.swift in Sources */,
244265
A7AC9F281B3493EB0041EB0B /* StringExtension.swift in Sources */,
266+
A7199EF01BFC134B00757E4F /* ThreadingHelper.swift in Sources */,
245267
A7F1DDB51B17D989001E9B94 /* UIWebViewDelegateMediator.swift in Sources */,
246-
A7F1DDBA1B17E6F5001E9B94 /* SupportedType.swift in Sources */,
247268
A7F1DDB81B17E5F8001E9B94 /* DataSerializer.swift in Sources */,
269+
A7199EEA1BFC038D00757E4F /* CaravelError.swift in Sources */,
270+
A7199EEC1BFC0EC700757E4F /* CaravelFactory.swift in Sources */,
248271
A7F1DDB21B17D989001E9B94 /* Caravel.swift in Sources */,
272+
A7199EEE1BFC11E000757E4F /* NSObjectExtension.swift in Sources */,
249273
A7F1DDBC1B17EF24001E9B94 /* ArgumentParser.swift in Sources */,
250274
);
251275
runOnlyForDeploymentPostprocessing = 0;
@@ -263,7 +287,7 @@
263287
/* Begin PBXTargetDependency section */
264288
A7F1DDA01B17D958001E9B94 /* PBXTargetDependency */ = {
265289
isa = PBXTargetDependency;
266-
target = A7F1DD911B17D957001E9B94 /* Caravel.temp_caseinsensitive_rename */;
290+
target = A7F1DD911B17D957001E9B94 /* Caravel */;
267291
targetProxy = A7F1DD9F1B17D958001E9B94 /* PBXContainerItemProxy */;
268292
};
269293
/* End PBXTargetDependency section */
@@ -433,7 +457,7 @@
433457
defaultConfigurationIsVisible = 0;
434458
defaultConfigurationName = Release;
435459
};
436-
A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_rename" */ = {
460+
A7F1DDA81B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel" */ = {
437461
isa = XCConfigurationList;
438462
buildConfigurations = (
439463
A7F1DDA91B17D958001E9B94 /* Debug */,
@@ -442,7 +466,7 @@
442466
defaultConfigurationIsVisible = 0;
443467
defaultConfigurationName = Release;
444468
};
445-
A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "Caravel.temp_caseinsensitive_renameTests" */ = {
469+
A7F1DDAB1B17D958001E9B94 /* Build configuration list for PBXNativeTarget "CaravelTests" */ = {
446470
isa = XCConfigurationList;
447471
buildConfigurations = (
448472
A7F1DDAC1B17D958001E9B94 /* Debug */,

README.md

Lines changed: 25 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Caravel
1+
![Caravel Logo](logo.png)
22

33
[![CocoaPods](https://img.shields.io/cocoapods/v/Caravel.svg?style=flat-square)](https://cocoapods.org/pods/Caravel)
44

@@ -8,21 +8,21 @@
88

99
## Features
1010

11-
* Easy event bus system
11+
* Easy, fast and reliable event bus system
1212
* Multiple bus support
13-
* `When Ready` event: do not miss any event from your lovely Swift controller!
13+
* Multithreading support
1414
* iOS ~> JavaScript supported types:
1515
- `Bool`
1616
- `Int`
1717
- `Float`
1818
- `Double`
1919
- `String`
20-
- `NSArray`
21-
- `NSDictionary`
20+
- Any array (using types in this list)
21+
- Any dictionary (using types in this list)
2222
* JavaScript ~> iOS supported types:
23-
- `Bool`
23+
- `Boolean`
2424
- `Int`
25-
- `Double`
25+
- `Float`
2626
- `String`
2727
- `Array` (available as a `NSArray`)
2828
- `Object` (available as a `NSDictionary`)
@@ -43,26 +43,33 @@ Once done, you should find a `caravel.min.js` file in either the Pod or the subm
4343
<script type="text/javascript" src="caravel.min.js"></script>
4444
```
4545

46+
## Migrate from 0.* to 1.*
47+
48+
[Please glance at this blog post](http://www.coshx.com/blog/2015/11/19/releasing-caravel-1-0-0/).
49+
4650
## Get started
4751

4852
Caravel allows developers to communicate between their `UIWebView` and the embedded JS. You can send any kind of message between those two folks.
4953

5054
Have a glance at this super simple sample. Let's start with the iOS part:
5155

5256
```swift
53-
import Caravel
54-
5557
class MyController: UIViewController {
5658
@IBOutlet weak var webView: UIWebView!
5759

5860
func viewDidLoad() {
5961
super.viewDidLoad()
6062

61-
Caravel.getDefault().whenReady() { bus in
62-
bus.post("AnEvent", anArray: [1, 2, 3])
63-
}
63+
// Prepare your bus before loading your web view's content
64+
Caravel.getDefault(self, webView: webView, whenReady: { bus in
65+
// The JS endpoint is ready to handle any event.
66+
// Register and post your events in this scope
67+
bus.post("MyEvent", data: [1, 2, 3])
68+
69+
self.bus = bus // You can save your bus for firing events later
70+
})
6471

65-
// Load web view content below
72+
// ... Load web view content below
6673
}
6774
}
6875
```
@@ -77,95 +84,17 @@ Caravel.getDefault().register("AnEvent", function(name, data) {
7784

7885
And voilà!
7986

80-
## API
81-
82-
### Swift - Caravel class
83-
84-
```swift
85-
/**
86-
* Returns the default bus
87-
*/
88-
static func getDefault(webView: UIWebView) -> Caravel
89-
```
90-
91-
```swift
92-
/**
93-
* Returns custom bus
94-
*/
95-
static func get(name: String, webView: UIWebView) -> Caravel
96-
```
97-
98-
```swift
99-
/**
100-
* Returns the current bus when its JS counterpart is ready
101-
*/
102-
func whenReady(callback: (Caravel) -> Void)
103-
```
104-
105-
```swift
106-
/**
107-
* Posts event without any argument
108-
*/
109-
func post(eventName: String)
110-
```
111-
112-
```swift
113-
/**
114-
* Posts event with extra data
115-
*/
116-
func post(eventName: String, anObject: AnyObject)
117-
```
118-
119-
**NB:** Caravel is smart enough for serializing nested objects (eg. an array wrapped into a dictionary) when posting an event. However, this serialization only works if nested types are supported ones.
120-
121-
```swift
122-
/**
123-
* Subscribes to provided event. Callback is run with the event's name and extra data
124-
*/
125-
func register(eventName: String, callback: (String, AnyObject?) -> Void)
126-
```
127-
128-
When receiving an event, you have to cast your data to the type you except. This cast is safe.
129-
130-
### JS - Caravel class
131-
132-
```js
133-
/**
134-
* Returns default bus
135-
*/
136-
static function getDefault()
137-
```
138-
139-
```js
140-
/**
141-
* Returns custom bus
142-
*/
143-
static function get(name)
144-
```
145-
146-
```js
147-
/**
148-
* Subscribes to provided event. Callback is called with event name first, then extra data if any
149-
*/
150-
static function register(name, callback)
151-
```
152-
153-
```js
154-
/**
155-
* Posts event. Data are optional
156-
*/
157-
static function post(name, data)
158-
```
159-
16087
## Troubleshooting
16188

162-
### I have my custom UIWebViewDelegate. What should I do?
89+
### I want to use my custom UIWebViewDelegate. What should I do?
16390

164-
Caravel saves the current delegate, if any, before setting its own. So, if you would like to use your custom one, you have to set it before any call to Caravel.
91+
To raise iOS events, Caravel must be the delegate of the provided `UIWebView`. However, if there is any existing delegate, Caravel saves it before setting its own. So, if you would like to use your custom one, simply set it before any call to Caravel.
16592

16693
### Reserved names
16794

16895
`CaravelInit` is an internal event, sent by the JS part for triggering the `whenReady` method.
16996

170-
Also, the default bus is named `default`. If you use that name for a custom bus, Caravel will automatically use the default one.
97+
Also, the default bus is named `default`. If you use that name for a custom bus, Caravel will automatically switch to the default one.
98+
99+
### Keep in mind event and bus names are case-sensitive.
171100

0 commit comments

Comments
 (0)