Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

Commit 9a83b7b

Browse files
author
devfd
committed
update documentation
1 parent 2c23a0a commit 9a83b7b

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

README.md

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
Spin worker threads and run CPU intensive tasks in the background. Bonus point on Android you can keep a worker alive even when a user quit the application :fireworks:
44

55
## Features
6-
- JS workers for iOS and Android
6+
- JS web workers for iOS and Android
77
- access to native modules (network, geolocation, storage ...)
88
- Android Services in JS :tada:
99

10-
## Warning
11-
This plugin is still in beta and some features are missing. Current restrictions include:
12-
- worker files are only loaded from http://localhost:8081.
13-
- worker files are not yet packaged with your application.
14-
- no HMR support. no hot-reload support.
15-
1610
## Installation
1711

1812
```bash
@@ -21,6 +15,10 @@ npm install react-native-workers --save
2115

2216
## Setup
2317

18+
### rnpm
19+
20+
simply `rnpm link react-native-workers` and you'r good to go.
21+
2422
### iOS
2523

2624
1. Open your project in XCode, right click on Libraries and click Add Files to "Your Project Name". Look under node_modules/react-native-workers/ios and add `Workers.xcodeproj`
@@ -44,32 +42,35 @@ dependencies {
4442
}
4543
```
4644

47-
and finally, in your `MainActivity.java` add:
45+
and finally, in your `MainApplication.java` add:
4846

4947
```java
5048

5149
import co.apptailor.Worker.WorkerPackage; // <--- This!
5250

53-
public class MainActivity extends ReactActivity {
54-
55-
@Override
56-
protected String getMainComponentName() {
57-
return "MyApp";
58-
}
59-
60-
@Override
61-
protected boolean getUseDeveloperSupport() {
62-
return BuildConfig.DEBUG;
63-
}
64-
65-
@Override
66-
protected List<ReactPackage> getPackages() {
67-
return Arrays.<ReactPackage>asList(
68-
new MainReactPackage(),
69-
new WorkerPackage() // <---- and This!
70-
);
71-
}
51+
public class MainApplication extends Application implements ReactApplication {
52+
53+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
54+
@Override
55+
protected boolean getUseDeveloperSupport() {
56+
return BuildConfig.DEBUG;
57+
}
58+
59+
@Override
60+
protected List<ReactPackage> getPackages() {
61+
return Arrays.<ReactPackage>asList(
62+
new MainReactPackage(),
63+
new WorkerPackage() // <--- and this
64+
);
65+
}
66+
};
67+
68+
@Override
69+
public ReactNativeHost getReactNativeHost() {
70+
return mReactNativeHost;
71+
}
7272
}
73+
7374
```
7475

7576
## JS API
@@ -79,7 +80,7 @@ From your application:
7980
import { Worker } from 'react-native-workers';
8081

8182
/* start worker */
82-
const worker = new Worker("path/to/js/worker");
83+
const worker = new Worker("path/to/worker.js");
8384

8485
/* post message to worker. String only ! */
8586
worker.postMessage("hello from application");
@@ -94,7 +95,7 @@ worker.terminate();
9495

9596
```
9697

97-
From your worker:
98+
From your worker js file:
9899
```js
99100
import { self } from 'react-native-workers';
100101

@@ -106,4 +107,16 @@ self.onmessage = (message) => {
106107
self.postMessage("hello from worker");
107108
```
108109

109-
##### Reload your application to restart your worker with the latest bundle version
110+
## Lifecycle
111+
112+
- the workers are paused when the app enters in the background
113+
- the workers are resumed once the app is running in the foreground
114+
- During development, when you reload the main JS bundle (shake device -> `Reload`) the workers are killed
115+
116+
## Todo
117+
118+
- [x] Android - download worker files from same location as main bundle
119+
- [ ] iOS - download worker files from same location as main bundle
120+
- [ ] script to package worker files for release build
121+
- [ ] load worker files from disk if not debug
122+

0 commit comments

Comments
 (0)