Skip to content

Commit d481914

Browse files
authored
Refactored main readme and fixed packages homepages (#38)
1 parent af70aff commit d481914

File tree

5 files changed

+22
-113
lines changed

5 files changed

+22
-113
lines changed

README.md

Lines changed: 13 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
src="https://res.cloudinary.com/daiqkausy/image/upload/v1596144724/windowed-observable.png"
99
/>
1010

11-
<p>Messaging lib using a pub/sub observable scoped by namespaces.</p>
11+
<p>The home for all windowed-observable projects</p>
1212
</div>
1313
<hr />
1414

@@ -19,115 +19,25 @@
1919
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style)](http://makeapullrequest.com)
2020
![Downloads](https://img.shields.io/npm/dt/windowed-observable)
2121

22-
**windowed-observable** is a library for messaging using Observables, making it easier to communicate multiple apps or parts of an app using the window. It exposes an Observable that behaves like a scoped Pub/Sub topic using namespaces.
23-
24-
## Installation
25-
```sh
26-
npm install windowed-observable
27-
28-
# or
29-
30-
yarn add windowed-observable
31-
```
32-
3322
## Introduction
3423

35-
An *observable* look like a pub/sub topic, there are scoped events and observers(listeners) on each namespace, and those namespaces can be cleared, and changed.
36-
37-
38-
## Usages
39-
40-
### Common usage
41-
```ts
42-
import { Observable } from 'windowed-observable';
43-
const observable = new Observable('konoha');
44-
observable.subscribe((ninja) => {
45-
console.log(ninja)
46-
})
47-
observable.publish('Uchiha Shisui');
48-
// > Uchiha Shisui
49-
```
50-
51-
### Retrieving latest event
52-
```ts
53-
import { Observable } from 'windowed-observable';
54-
55-
const observable = new Observable('konoha');
56-
57-
observable.publish('Senju Tobirama');
58-
59-
observable.subscribe((ninja) => console.log(ninja), { latest: true });
60-
// > Senju Tobirama
61-
```
62-
63-
### Unsubscribing and clearing
64-
```ts
65-
import { Observable } from 'windowed-observable';
66-
67-
const observable = new Observable('konoha');
68-
69-
const observer = (ninja) => console.log(ninja);
70-
71-
observable.subscribe(observer)
72-
observable.publish('Uzumaki Naruto');
73-
// > Uzumaki Naruto
74-
75-
// Unsubscribing
76-
observable.unsubscribe(observer);
77-
78-
// Clearing
79-
observable.clear();
80-
```
81-
82-
### React
83-
84-
Simple react usage
85-
86-
#### Observer component
87-
```tsx
88-
import React, { Component } from 'react';
89-
import { Observable } from 'windowed-observable';
90-
91-
const observable = new Observable('konoha');
92-
93-
class NinjasList extends Component {
94-
state: {
95-
ninjas: []
96-
}
97-
98-
componentDidMount() {
99-
this.observer = (ninja) => {
100-
const ninjas = this.state.ninjas.concat(ninja);
101-
102-
this.setState({ ninjas });
103-
}
104-
105-
observable.subscribe(this.observer);
106-
}
24+
### Problem
10725

108-
componentWillUnmount() {
109-
observable.unsubscribe(this.observer);
110-
}
26+
In a micro frontends setup, one of the main problems is [cross application communication](https://dev.to/luistak/cross-micro-frontends-communication-30m3) and this library aims to solve it by providing a simple and framework agnostic API with zero configuration
11127

112-
render() {
113-
...
114-
// ninjas listing
115-
}
116-
}
117-
```
28+
### Solution
11829

119-
#### Publisher component
30+
Exposing an `observable` that behaves like scoped a pub/sub topic passing events per namespaces.
12031

121-
```tsx
122-
import React from 'react';
123-
import { Observable } from 'windowed-observable';
32+
This `Observable` is exported by the core package [`windowed-observable`](packages/core/REAMDE.md) with the following features:
12433

125-
const observable = new Observable('konoha');
34+
### ✨ Features
35+
- 📦 Scoped events by `namespaces`
36+
- 🎣 Events history retrieval with `SubscriptionOptions`
37+
- 🛡 100% Written in TypeScript with static types
12638

127-
const handleClick = ninja = () => observable.publish(ninja);
39+
## Packages
12840

129-
const AddNinjaButton = ({ ninja }) => (
130-
<button onClick={handleClick(ninja)}> Add ninja </button>
131-
);
132-
```
41+
- [**windowed-observable**](packages/core/REAMDE.md) is a library for messaging using Observables, making it easier to communicate multiple apps or parts of an app using the window. It exposes an Observable that behaves like a scoped pub/sub topic using namespaces.
13342

43+
- [**react-windowed-observable**](packages/react/REAMDE.md) is a react abstraction over [`windowed-observable`](packages/core/REAMDE.md) exposing a helper that creates a scoped [`Context`](https://reactjs.org/docs/context.html) to handle events in a specific namespace

packages/core/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
**windowed-observable** is a library for messaging using Observables, making it easier to communicate multiple apps or parts of an app using the window. It exposes an Observable that behaves like a scoped Pub/Sub topic using namespaces.
2323

24-
## Installation
24+
## 📦 Installation
2525
```sh
2626
npm install windowed-observable
2727

@@ -30,12 +30,11 @@ npm install windowed-observable
3030
yarn add windowed-observable
3131
```
3232

33-
## Introduction
33+
## ⌨️ Introduction
3434

3535
An *observable* look like a pub/sub topic, there are scoped events and observers(listeners) on each namespace, and those namespaces can be cleared, and changed.
3636

37-
38-
## Usages
37+
## 🔨 Usages
3938

4039
### Common usage
4140
```ts
@@ -124,7 +123,7 @@ import { Observable } from 'windowed-observable';
124123

125124
const observable = new Observable('konoha');
126125

127-
const handleClick = ninja = () => observable.publish(ninja);
126+
const handleClick = ninja => () => observable.publish(ninja);
128127

129128
const AddNinjaButton = ({ ninja }) => (
130129
<button onClick={handleClick(ninja)}> Add ninja </button>

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"bugs": {
3232
"url": "https://github.com/luistak/windowed-observable/issues"
3333
},
34-
"homepage": "https://github.com/luistak/windowed-observable#readme",
34+
"homepage": "https://github.com/luistak/windowed-observable/tree/master/packages/core#readme",
3535
"husky": {
3636
"hooks": {
3737
"pre-commit": "tsdx lint"

packages/react/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
**react-windowed-observable** is a react library for messaging using Observables, making it easier to communicate multiple apps or parts of an app using the window.
2323

2424

25-
## Installation
25+
## 📦 Installation
2626
```sh
2727
npm install react-windowed-observable
2828

@@ -31,13 +31,13 @@ npm install react-windowed-observable
3131
yarn add react-windowed-observable
3232
```
3333

34-
## Introduction
34+
## ⌨️ Introduction
3535

3636
It exposes a hook to use and publish data using an Observable;
3737

3838
An *observable* look like a pub/sub topic, there are scoped events and observers(listeners) on each namespace, and those namespaces can be cleared, and changed.
3939

40-
## Examples
40+
## 🔨 Usages
4141

4242
### Basic example
4343
```tsx

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"bugs": {
1414
"url": "https://github.com/luistak/windowed-observable/issues"
1515
},
16-
"homepage": "https://github.com/luistak/windowed-observable/tree/master/packages/react-windowed-observable",
16+
"homepage": "https://github.com/luistak/windowed-observable/tree/master/packages/react#readme",
1717
"files": [
1818
"dist",
1919
"src"

0 commit comments

Comments
 (0)