Skip to content

Commit

Permalink
docs: Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
finom committed May 30, 2023
1 parent dbdda2d commit 3af84fc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class Users extends Use0 {

const users = new Users();

export default users;
export default users; // default export of the instance instead of the class
```
Then call `init` for every sub-store you have.
Expand Down Expand Up @@ -641,7 +641,7 @@ export class UsersPublic extends Use0 {
// ./store/users/protected.ts
import { UsersPublic } from './public';

export class Users extends UsersPublic {
export class UsersProtected extends UsersPublic {
private store!: RootStore;
readonly loadUsers = async () => {
console.log(this.ids);
Expand All @@ -653,12 +653,12 @@ export class Users extends UsersPublic {
```ts
// ./store/users/index.ts
import { UsersPublic } from './public';
import { Users } from './protected';
import { UsersProtected } from './protected';

const users = new Users();
const users = new UsersProtected();

export const { loadUsers } = users;
export type { Users }; // re-export for lower-level sub-stores
export type { UsersProtected }; // re-export for lower-level sub-stores
export default users as UsersPublic;
```

Expand All @@ -680,8 +680,6 @@ Your file structure is going to look like that:
/protected.ts
```



### Conclusion

1. Using patterns above we restrict the code and provide only one way to import the store by component modules: `import publicData, { method1, method2 } from './store/foo/bar/baz` where default export is used for "data" and named export is used for actions. It doesn't make sense to provide full store access to other modules that aren't related to the store.
Expand Down

0 comments on commit 3af84fc

Please sign in to comment.