Skip to content

Commit

Permalink
update: Readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
weixiangmeng521 committed Dec 20, 2023
1 parent e9e31c8 commit a4daa25
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,58 @@ npm install @mwx47/teleport

## Usage

### First Example
```typescript
import { Teleport } from '@mwx47/teleport';

const teleport = new Teleport();

// send data
teleport.emit('eventName', "hello world!");

teleport.receive('eventName', (data) => {
console.log('Event data:', data); // ✅ hello world!
});
```


### Examples with delayed subscription
```typescript
import { Teleport } from '@mwx47/teleport';

const teleport = new Teleport();
// send data
teleport.emit('eventName', "hello world!");

// Although it is delayed by 1000ms, the data can still be obtained
setTimeout(() => {
teleport.receive('eventName', (data) => {
console.log('Event data:', data); // ✅ hello world!
});
}, 1000);
```



### Examples with multiple subscriptions
```typescript
import { Teleport } from '@mwx47/teleport';

const teleport = new Teleport();
// send data
teleport.emit('eventName1', "Tokyo!");
teleport.emit('eventName2', "China!");
teleport.emit('eventName3', "London!");

const subscriptions = ['eventName1', 'eventName2', 'eventName3'];
teleport.receive(subscriptions, (arg1:string, arg2:string, arg3:string) => {
console.log('Hello', arg1); // ✅ Hello Tokyo!
console.log('Hello', arg1); // ✅ Hello China!
console.log('Hello', arg1); // ✅ Hello London!
});
```


### Importing

```typescript
Expand Down

0 comments on commit a4daa25

Please sign in to comment.