Skip to content

Commit

Permalink
TW-692: Add ADR for send/listen event
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Oct 3, 2023
1 parent 7cdfe74 commit 8c89530
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions docs/adr/0009-Instructions-for-naming-twake-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 7. Instructions for naming twake events

Date: 2023-10-03

## Status

Accepted

## Docs

- [Spec](https://spec.matrix.org/v1.6/#events)

## Context

- All data exchanged through Matrix is represented as an “event”. In addition, we have local support events.
- We can use local events to handle logic and behavior by injecting events into a defined stream.

## How to name events
- Below are the naming rules for events.
- App.twake is the name of the application.
- Inapp is event use for local support.
- Profile is the name of the feature.
- Avatar is the name of the event.
ex: 'app.twake.inapp.profile.avatar'

## How to use events.
- Send event

```
class TwakeEventDispatcher {
static final TwakeEventDispatcher _twakeEventDispatcher =
TwakeEventDispatcher._instance();
factory TwakeEventDispatcher() {
return _twakeEventDispatcher;
}
TwakeEventDispatcher._instance();
void sendAccountDataEvent({
required Client client,
required BasicEvent basicEvent,
}) {
client.onAccountData.add(basicEvent);
}
}
twakeEventDispatcher.sendAccountDataEvent(
client: client,
basicEvent: BasicEvent(
type: TwakeInappEventTypes.uploadAvatarEvent,
content: profile.toJson(),
),
);
```
- Listen event and handle it

```
client.onAccountData.stream.listen((event) {
Logs().d(
'FetchProfileMixin::onAccountData() - EventType: ${event.type} - EventContent: ${event.content}',
);
if (event.type == TwakeInappEventTypes.uploadAvatarEvent) {
profileNotifier.value = Profile.fromJson(event.content);
}
});
```

0 comments on commit 8c89530

Please sign in to comment.