Skip to content

Instantly share code, notes, and snippets.

@nguyenchilong
Created July 5, 2020 09:06
Show Gist options
  • Save nguyenchilong/c0b36a3d302660205f404285dd39d9b3 to your computer and use it in GitHub Desktop.
Save nguyenchilong/c0b36a3d302660205f404285dd39d9b3 to your computer and use it in GitHub Desktop.

Revisions

  1. nguyenchilong created this gist Jul 5, 2020.
    16 changes: 16 additions & 0 deletions notification_reducer.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    final notificationReducer = combineReducers<NotificationState>([
    TypedReducer<NotificationState, SyncNotificationsAction>(_syncNotifications),
    ]);

    NotificationState _syncNotifications(
    NotificationState state, SyncNotificationsAction action) {
    for (var notification in action.notifications) {
    state.notifications.update(notification.id.toString(), (v) => notification,
    ifAbsent: () => notification);
    }
    state.page.currPage = action.page.currPage;
    state.page.pageSize = action.page.pageSize;
    state.page.totalCount = action.page.totalCount;
    state.page.totalPage = action.page.totalPage;
    return state.copyWith(notifications: state.notifications);
    }