Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.
/ ReduRx Public archive

๐Ÿ‘Œ A thin layer of a Redux-based state manager on top of RxDart

License

Notifications You must be signed in to change notification settings

leocavalcante/ReduRx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ReduRx Build Status

๐Ÿ‘Œ A thin layer of a Redux-based state manager on top of RxDart.

Flutter bindings โ€ข React bindings

Getting started

Usage

import 'dart:async';
import 'package:redurx/redurx.dart';

class State {
  State(this.count);
  final int count;

  @override
  String toString() => count.toString();
}

class Increment extends Action<State> {
  Increment([this.by = 1]);
  final int by;
  State reduce(State state) => State(state.count + by);
}

class AsyncIncrement extends AsyncAction<State> {
  @override
  Future<Computation<State>> reduce(State state) async {
    int result = await doAsyncTask();
    return (State state) =>
      State(count: state.count + result);
    }
  }
}

void main() {
  final store = Store<State>(State(0));

  store.add(LogMiddleware<State>());
  print(store.state.count); // 0

  store.dispatch(Increment());
  // Before action: Increment: 0 (from LogMiddleware)
  // After action: Increment: 1 (from LogMiddleware)
  print(store.state.count); // 1

  store.dispatch(Increment(2));
  // Before action: Increment: 1 (from LogMiddleware)
  // After action: Increment: 3 (from LogMiddleware)
  print(store.state.count); // 3
}

Just give it a try. Feel free to open Issues and PRs!

About

๐Ÿ‘Œ A thin layer of a Redux-based state manager on top of RxDart

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages