Skip to content

Commit 5de34c5

Browse files
author
pioner921227
committed
updated README
1 parent 119fdfa commit 5de34c5

File tree

2 files changed

+90
-14
lines changed

2 files changed

+90
-14
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,109 @@
1-
# react-native-sync-tasks
1+
# πŸš€ SyncTasksManager (JSI)
22

3-
api sync tasks
3+
<p align="center">
4+
<img src="./assets/img.png" width="600"/>
5+
</p>
46

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.
68

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+
- ✨ Built-in response deduplication using response body hash β€” avoids redundant `onData` calls if the response has not changed
19+
20+
---
21+
22+
## πŸ“¦ Installation
23+
24+
> You need to properly install and link the native JSI module `SyncTasksManager` on both iOS and Android.
25+
26+
```bash
27+
# Install your native module here (replace with real package)
28+
npm install react-native-sync-tasks-manager
929
```
1030

11-
## Usage
31+
> Don’t forget to run `pod install` for iOS if using CocoaPods.
32+
33+
---
1234

35+
## πŸ› οΈ Usage
1336

14-
```js
15-
import { multiply } from 'react-native-sync-tasks';
37+
```ts
38+
import { createTask, SyncTasksManager } from 'react-native-sync-tasks-manager';
1639

17-
// ...
40+
const task = createTask<{ response: string }>({
41+
config: {
42+
url: 'https://jsonplaceholder.typicode.com/posts/1',
43+
interval: 2000,
44+
headers: {
45+
'Content-Type': 'application/json',
46+
'Accept': 'application/json',
47+
},
48+
},
49+
onData: (data) => {
50+
console.log('DATA', data);
51+
},
52+
onError: (error) => {
53+
console.log('ERROR', error);
54+
},
55+
});
1856

19-
const result = multiply(3, 7);
57+
SyncTasksManager.addTask(task);
58+
SyncTasksManager.startAll();
2059
```
2160

61+
---
62+
63+
## πŸ” API
64+
65+
### `createTask<T>(props: TCreateTaskProps<T>): Task`
66+
67+
Creates a background task that will periodically fetch data from the specified URL.
2268

23-
## Contributing
69+
#### Props:
2470

25-
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
71+
| Name | Type | Description |
72+
|-----------|----------------------------------------------------------------------|-----------------------------------------------|
73+
| `config` | `{ url: string; interval: number; headers?: Record<string, string> }` | HTTP polling configuration |
74+
| `onData` | `(data: T) => void` | Callback when data is successfully received |
75+
| `onError` | `(error: { error: string; body?: string; code: number }) => void` | Callback when request fails (optional) |
76+
77+
> Under the hood, the task stores a hash of the last response body. If the newly fetched response is identical (hash matches), the `onData` callback will **not** be triggered.
78+
79+
### `Task`
80+
81+
Represents an individual background sync task.
82+
83+
#### Methods:
84+
85+
- `start(): void` β€” Manually start the task
86+
- `stop(): void` β€” Stop the task
87+
- `isRunning(): boolean` β€” Check if the task is currently running
88+
89+
---
90+
91+
### `SyncTasksManager`
92+
93+
A global task manager for controlling multiple tasks at once.
94+
95+
#### Methods:
96+
97+
- `addTask(task: Task): void` β€” Add a single task
98+
- `addTasks(tasks: Task[]): void` β€” Add multiple tasks
99+
- `startAll(): void` β€” Start all registered tasks
100+
- `stopAll(): void` β€” Stop all running tasks
101+
102+
---
26103

27-
## License
104+
## πŸ“„ License
28105

29106
MIT
30107

31108
---
32109

33-
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

β€Žassets/img.pngβ€Ž

70.5 KB
Loading

0 commit comments

Comments
Β (0)