Skip to content

Commit a8edd92

Browse files
authored
Update docs (#53)
* Update docs * fix * Add more docs * Update package.json
1 parent b70f074 commit a8edd92

2 files changed

Lines changed: 67 additions & 5 deletions

File tree

README.md

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ _Tiny, easy and powerful **React state management** library_
4545
- [Use more than one store](#use-more-than-one-store)
4646
- [Update several portions avoiding rerenders in the rest](#update-several-portions-avoiding-rerenders-in-the-rest)
4747
- [Define calculated properties](#define-calculated-properties)
48-
- [6. Examples 🖥](#examples-)
49-
- [7. Roadmap 🛣](#roadmap-)
50-
- [8. Contributors ✨](#contributors-)
48+
- [6. Teaful Devtools 🛠](#teaful-devtools-)
49+
- [7. Addons and extras 🌀](#addons-and-extras-)
50+
- [8. Examples 🖥](#examples-)
51+
- [9. Roadmap 🛣](#roadmap-)
52+
- [10. Contributors ✨](#contributors-)
5153

5254
## Installation 🧑🏻‍💻
5355

@@ -558,6 +560,57 @@ function onAfterUpdate({ store }) {
558560
}
559561
```
560562

563+
It's an anti-pattern? Not in Teaful 😊. As only the fragments of the store are updated and not the whole store, it is the same as updating both properties (`cart.items` and `cart.price`) instead of just `cart.items`. The anti-pattern comes when it causes unnecessary rerenders, but this is not the case. Only the components that use `cart.items` and `cart.price` are rerendered and not the others.
564+
565+
566+
## Teaful Devtools 🛠
567+
568+
To debug your stores, you can use [Teaful DevTools](https://github.com/teafuljs/teaful-devtools).
569+
570+
<img alt="Teaful DevTools" src="https://github.com/teafuljs/teaful-devtools/blob/master/demo.png?raw=true" />
571+
572+
573+
## Addons and extras 🌀
574+
575+
To facilitate the creation of libraries that extend Teaful (such as [`teaful-devtools`](https://github.com/teafuljs/teaful-devtools)), we allow the possibility to add an extra that:
576+
577+
- Have access to everything returned by each `createStore` consumed: `getStore`, `useStore`, `withStore`.
578+
- Return an object with new elements to be returned by each `createStore`. It's optional, if nothing is returned it will continue to return the usual. If, for example, you return `{ getCustomThing }` will do an assign with what is currently returned by the `createStore`.
579+
- Ability to **subscribe**, **unsubscribe** and **notify** in each `createStore`.
580+
581+
For that, use the `createStore.ext` function.
582+
583+
<small>teaful-yourlib:</small>
584+
585+
```js
586+
import createStore from 'teaful'
587+
588+
createStore.ext(({ getStore, }, subscription) => {
589+
// s = subscribe (minified by Teaful)
590+
// "." -> all store
591+
// ".cart" -> only inside cart
592+
// ".cart.price" -> only inside cart.price
593+
// n = notify (minified by Teaful)
594+
// u = unsubscribe (minified by Teaful)
595+
subscription.s(".", ({ store, prevStore }) => {
596+
// This will be executed in any store (".") change.
597+
});
598+
599+
// optional
600+
return { getCustomThing: () => console.log('example') }
601+
})
602+
```
603+
604+
Then, your library should be imported at the top:
605+
606+
```js
607+
import 'teaful-yourlib'
608+
import { render } from 'preact';
609+
import App from './components/App';
610+
611+
render(<App />, document.getElementById('root'));
612+
```
613+
561614
## Examples 🖥
562615

563616
We will expand the examples over time. For now you can use this Codesandbox:
@@ -567,7 +620,10 @@ We will expand the examples over time. For now you can use this Codesandbox:
567620
## Roadmap 🛣
568621

569622
- [x] React support
570-
- [x] TypeScript support
623+
- [x] Teaful DevTools
624+
- [ ] TypeScript support
625+
- [x] Add TypeScript types
626+
- [ ] Migrate full Teaful project to TypeScript
571627
- [ ] Vanilla JavaScript support
572628
- [ ] Svelte support
573629
- [ ] Vue support

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@
6565
"prepublish": "yarn build"
6666
},
6767
"peerDependencies": {
68-
"react": ">= 16.8.0"
68+
"react": ">= 16.8.0",
69+
"teaful-devtools": ">= 0.4.0"
70+
},
71+
"peerDependenciesMeta": {
72+
"teaful-devtools": {
73+
"optional": true
74+
}
6975
},
7076
"jest": {
7177
"testEnvironment": "jsdom",

0 commit comments

Comments
 (0)