entity_state 1.2.3

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.1

Usage #

In your redux state

abstract class ReminderState
    with EntityState<Reminder, int, ReminderState, ReminderStateBuilder>
    implements Built<ReminderState, ReminderStateBuilder> {
  // This is mandatory to add
  BuiltList<int> get ids;

  // This is mandatory to add
  BuiltMap<int, Reminder> get entities;

  ReminderState._();

  factory ReminderState([updates(ReminderStateBuilder b)]) = _$ReminderState;

  static Serializer<ReminderState> 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<Notification>`
      .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<Notification>`
      .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<Notification>`
      .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<Notification>`
      .removeMany(action.notifications)
      .rebuild((b) => b..isLoading = false);
}

To Remove All #

AppNotificationState listNotificationComplete(
    AppNotificationState appNotificationState,
    ListNotificationComplete action) {
  return appNotificationState
        // action.notifications is `List<Notification>`
      .removeAll()
      .rebuild((b) => b..isLoading = false);
}

How to get the data #

static _ViewModel fromStore(Store<AppState> store) {
       return _ViewModel(
           notifications: store.state.appNotification.getAll(),
           isLoading: store.state.appNotification.isLoading,
           notificationTapped: (AppNotification notification) {
             store.dispatch(UpdateNotification(notification: notification));
           });
     }

[1.0.0] - April 2, 2019

[1.2.0] - July 7, 2019

example/README.md

example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  entity_state: ^1.2.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:entity_state/entity_state.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
57
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Jul 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:entity_state/entity_state.dart.

Health suggestions

Fix lib/entity_state.dart. (-1 points)

Analysis of lib/entity_state.dart reported 2 hints:

line 59 col 21: Avoid types as parameter names.

line 114 col 25: Use isEmpty instead of length

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
built_collection ^4.2.0 4.2.2
Transitive dependencies
collection 1.14.11
matcher 0.12.5
meta 1.1.7
path 1.6.2
quiver 2.0.3
stack_trace 1.9.3

Admin