-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from w11k/repository_poc
_Tydux Repository_ adds a repository state using `createRepositoryState` with prebuild CRUD operations by extending your Tydux Commands with `RepositoryCommands`. This empowers you to quickly **add/update/delete** data on a normalized state structure. **The following operations are available:** - **updateOrPushEntry**: add or update one entry - **updateOrPushEntries**: add or update multiple entries - **setPositionOfEntry**: set position of one entry to the start, the end or a specific index of the list - **setPositionOfEntries**: set position of multiple entries to the start, the end or a specific index of the list - **patchEntry**: patch one partial entry - **patchEntries**: patch multiple partial entries - **removeEntry**: removes one entry - **removeEntries**: remove multiple entries - **removeAllEntries**: clear all repository entries The normalized state can be created like the following: - **createRepositoryState(idField)**: create an empty repository state - **createRepositoryState(idField, {})**: create a repository state with an initial value (object) - **createRepositoryState(idField, [])**: create a repository state with an initial value (array)
- Loading branch information
Showing
10 changed files
with
780 additions
and
11,061 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Tydux Repository | ||
|
||
_Tydux Repository_ adds a repository state using `createRepositoryState` with prebuild CRUD operations by extending your Tydux Commands with | ||
`RepositoryCommands`. | ||
This empowers you to quickly **add/update/delete** data on a normalized state structure. | ||
|
||
**The following operations are available:** | ||
|
||
- **updateOrPushEntry**: add or update one entry | ||
- **updateOrPushEntries**: add or update multiple entries | ||
- **setPositionOfEntry**: set position of one entry to the start, the end or a specific index of the list | ||
- **setPositionOfEntries**: set position of multiple entries to the start, the end or a specific index of the list | ||
- **patchEntry**: patch one partial entry | ||
- **patchEntries**: patch multiple partial entries | ||
- **removeEntry**: removes one entry | ||
- **removeEntries**: remove multiple entries | ||
- **removeAllEntries**: clear all repository entries | ||
|
||
The normalized state can be created like the following: | ||
|
||
- **createRepositoryState(idField)**: create an empty repository state | ||
- **createRepositoryState(idField, {})**: create a repository state with an initial value (object) | ||
- **createRepositoryState(idField, [])**: create a repository state with an initial value (array) | ||
|
||
|
||
## Quick usage | ||
|
||
```typescript | ||
class TodoState { | ||
todos = createRepositoryState<Todo, "id">("id"); | ||
} | ||
|
||
class TodoCommands extends RepositoryCommands<TodoState> { | ||
// .... other custom commands | ||
} | ||
|
||
class TodoFacade extends Facade<TodoCommands> { | ||
addOne(todo: Todo) { | ||
this.commands.updateOrPushEntry("todos", todo); | ||
} | ||
} | ||
|
||
export class TodoService extends TodoFacade { | ||
|
||
constructor() { | ||
super("todos", new TodoCommands(), new TodoState()); | ||
} | ||
|
||
addTodo() { | ||
this.addOne({ id: '1', state: true, text: 'foo' }); | ||
} | ||
} | ||
``` | ||
|
||
(more examples see [repository.test.ts](https://github.com/w11k/Tydux/blob/master/modules/tydux/src/lib/repository.test.ts)) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.