|
1 | | -# react-native-sync-tasks |
| 1 | +# π SyncTasksManager (JSI) |
2 | 2 |
|
3 | | -api sync tasks |
| 3 | +<p align="center"> |
| 4 | +<img src="./assets/img.png" width="400"/> |
| 5 | +</p> |
4 | 6 |
|
5 | | -## Installation |
| 7 | +**SyncTasksManager** is a native JSI-based library for React Native that allows you to manage and execute background sync tasks (such as periodic API polling) efficiently from JavaScript, while delegating the actual execution to the native layer for better performance. |
6 | 8 |
|
7 | | -```sh |
8 | | -npm install react-native-sync-tasks |
| 9 | +--- |
| 10 | + |
| 11 | +## βοΈ Features |
| 12 | + |
| 13 | +- π Periodic HTTP polling with configurable interval |
| 14 | +- π‘ Callback on data reception or error |
| 15 | +- π§΅ High-performance task execution via JSI |
| 16 | +- π§ Centralized task management (start/stop all tasks) |
| 17 | +- β
Seamless integration with native modules (C++/JSI) |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## π¦ Installation |
| 22 | + |
| 23 | +> You need to properly install and link the native JSI module `SyncTasksManager` on both iOS and Android. |
| 24 | +
|
| 25 | +```bash |
| 26 | +# Install your native module here (replace with real package) |
| 27 | +npm install react-native-sync-tasks-manager |
9 | 28 | ``` |
10 | 29 |
|
11 | | -## Usage |
| 30 | +> Donβt forget to run `pod install` for iOS if using CocoaPods. |
| 31 | +
|
| 32 | +--- |
12 | 33 |
|
| 34 | +## π οΈ Usage |
13 | 35 |
|
14 | | -```js |
15 | | -import { multiply } from 'react-native-sync-tasks'; |
| 36 | +```ts |
| 37 | +import { createTask, SyncTasksManager } from 'react-native-sync-tasks-manager'; |
16 | 38 |
|
17 | | -// ... |
| 39 | +const task = createTask<{ response: string }>({ |
| 40 | + config: { |
| 41 | + url: 'https://jsonplaceholder.typicode.com/posts/1', |
| 42 | + interval: 2000, |
| 43 | + headers: { |
| 44 | + 'Content-Type': 'application/json', |
| 45 | + 'Accept': 'application/json', |
| 46 | + }, |
| 47 | + }, |
| 48 | + onData: (data) => { |
| 49 | + console.log('DATA', data); |
| 50 | + }, |
| 51 | + onError: (error) => { |
| 52 | + console.log('ERROR', error); |
| 53 | + }, |
| 54 | +}); |
18 | 55 |
|
19 | | -const result = multiply(3, 7); |
| 56 | +SyncTasksManager.addTask(task); |
| 57 | +SyncTasksManager.startAll(); |
20 | 58 | ``` |
21 | 59 |
|
| 60 | +--- |
22 | 61 |
|
23 | | -## Contributing |
| 62 | +## π API |
24 | 63 |
|
25 | | -See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. |
| 64 | +### `createTask<T>(props: TCreateTaskProps<T>): Task` |
26 | 65 |
|
27 | | -## License |
| 66 | +Creates a background task that will periodically fetch data from the specified URL. |
28 | 67 |
|
29 | | -MIT |
| 68 | +#### Props: |
| 69 | + |
| 70 | +| Name | Type | Description | |
| 71 | +|-----------|----------------------------------------------------------------------|-----------------------------------------------| |
| 72 | +| `config` | `{ url: string; interval: number; headers?: Record<string, string> }` | HTTP polling configuration | |
| 73 | +| `onData` | `(data: T) => void` | Callback when data is successfully received | |
| 74 | +| `onError` | `(error: { error: string; body?: string; code: number }) => void` | Callback when request fails (optional) | |
| 75 | + |
| 76 | +### `Task` |
| 77 | + |
| 78 | +Represents an individual background sync task. |
| 79 | + |
| 80 | +#### Methods: |
| 81 | + |
| 82 | +- `start(): void` β Manually start the task |
| 83 | +- `stop(): void` β Stop the task |
| 84 | +- `isRunning(): boolean` β Check if the task is currently running |
30 | 85 |
|
31 | 86 | --- |
32 | 87 |
|
33 | | -Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
| 88 | +### `SyncTasksManager` |
| 89 | + |
| 90 | +A global task manager for controlling multiple tasks at once. |
| 91 | + |
| 92 | +#### Methods: |
| 93 | + |
| 94 | +- `addTask(task: Task): void` β Add a single task |
| 95 | +- `addTasks(tasks: Task[]): void` β Add multiple tasks |
| 96 | +- `startAll(): void` β Start all registered tasks |
| 97 | +- `stopAll(): void` β Stop all running tasks |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## π License |
| 102 | + |
| 103 | +MIT |
| 104 | + |
| 105 | +--- |
0 commit comments