https://github.com/devslane/entity_state
Flutter Redux Entity State inspired from Angular Entity State https://ngrx.io/guide/entity
https://github.com/devslane/entity_state
built-value entity-state flutter flutter-redux redux
Last synced: 8 months ago
JSON representation
Flutter Redux Entity State inspired from Angular Entity State https://ngrx.io/guide/entity
- Host: GitHub
- URL: https://github.com/devslane/entity_state
- Owner: devslane
- License: bsd-2-clause
- Created: 2019-04-18T08:50:32.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-12T06:20:48.000Z (almost 7 years ago)
- Last Synced: 2025-10-23T04:56:49.477Z (8 months ago)
- Topics: built-value, entity-state, flutter, flutter-redux, redux
- Language: Dart
- Homepage:
- Size: 107 KB
- Stars: 7
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Entity State
Entity State to manage records in your redux state.
## Installation
Add this to your project's pubspec.yaml
```
dependencies:
entity_state: ^1.2.5
```
## Usage
In your redux state
```
abstract class ReminderState
with EntityState
implements Built {
// This is mandatory to add
BuiltList get ids;
// This is mandatory to add
BuiltMap get entities;
ReminderState._();
factory ReminderState([updates(ReminderStateBuilder b)]) = _$ReminderState;
static Serializer get serializer => _$reminderStateSerializer;
// This will tell the entity state what is the unique identifier of the model.
@override
int getId(Reminder data) {
return data.id;
}
}
```
In your reducer
### To Add One
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notification is `Notification`
.addOne(action.notification)
.rebuild((b) => b..isLoading = false);
}
```
### To Add All (replaces any data that was previously present)
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notifications is `List`
.addAll(action.notifications)
.rebuild((b) => b..isLoading = false);
}
```
### To Add Many (appends to previous data)
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notifications is `List`
.addMany(action.notifications)
.rebuild((b) => b..isLoading = false);
}
```
### To Update One
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notification is `Notification`
.updateOne(action.notification)
.rebuild((b) => b..isLoading = false);
}
```
### To Update Many
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notifications is `List`
.updateMany(action.notifications)
.rebuild((b) => b..isLoading = false);
}
```
### To Remove One
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notification is `int`
.removeOne(action.notificationId)
.rebuild((b) => b..isLoading = false);
}
```
### To Remove Many
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notifications is `List`
.removeMany(action.notifications)
.rebuild((b) => b..isLoading = false);
}
```
### To Remove All
```
AppNotificationState listNotificationComplete(
AppNotificationState appNotificationState,
ListNotificationComplete action) {
return appNotificationState
// action.notifications is `List`
.removeAll()
.rebuild((b) => b..isLoading = false);
}
```
### How to get the data
```
static _ViewModel fromStore(Store store) {
return _ViewModel(
notifications: store.state.appNotification.getAll(),
isLoading: store.state.appNotification.isLoading,
notificationTapped: (AppNotification notification) {
store.dispatch(UpdateNotification(notification: notification));
});
}
```
### How to get the sorted data
```
static _ViewModel fromStore(Store store) {
return _ViewModel(
notifications: store.state.appNotification.getAll((notif1,notif2)=>notif1.id.compareTo(notif2.id),
});
}
```