https://github.com/bgildson/redux_prism
Library used to easily access dispatched actions in a Redux Store.
https://github.com/bgildson/redux_prism
actions dart flutter redux
Last synced: 9 months ago
JSON representation
Library used to easily access dispatched actions in a Redux Store.
- Host: GitHub
- URL: https://github.com/bgildson/redux_prism
- Owner: bgildson
- License: mit
- Created: 2019-05-31T01:33:38.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-05T03:15:06.000Z (over 6 years ago)
- Last Synced: 2024-08-22T19:37:13.880Z (almost 2 years ago)
- Topics: actions, dart, flutter, redux
- Language: Dart
- Homepage:
- Size: 68.4 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# redux_prism
[](https://travis-ci.org/bgildson/redux_prism)
[](https://coveralls.io/github/bgildson/redux_prism?branch=master)
[](https://pub.dartlang.org/packages/redux_prism)
Library used to easily access dispatched actions in a [Redux](https://pub.dartlang.org/packages/redux) Store. The library defines a pattern to catch new dispatched actions and listen to them in a reactive context. The `StorePrism.middleware` works like a proxy in the store middlewares and add every new action in the `StorePrism.actions` stream.
## Usage
```dart
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:redux_prism/redux_prism.dart';
void main() => runApp(MessageApp());
class MessageApp extends StatelessWidget {
Widget build(BuildContext context) =>
StoreProvider(
store: Store(
(state, action) => state,
middleware: [
// register StorePrism "proxy" middleware
StorePrism.middleware
],
),
child: MaterialApp(
title: 'Redux Prism',
home: MessagePage()
),
);
}
@immutable
class MessageAction {
final String message;
MessageAction({this.message});
@override
String toString() => 'MessageAction { message: $message }';
}
class MessagePage extends StatelessWidget {
final GlobalKey _scaffoldKey = GlobalKey();
final TextEditingController _messageController = TextEditingController();
MessagePage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) =>
StorePrismListener(
listen: (action) =>
_scaffoldKey.currentState
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(action.toString()))),
child: Scaffold(
key: _scaffoldKey,
appBar: AppBar(title: Text('Redux Prism')),
body: Column(
children: [
TextField(
controller: _messageController,
decoration: InputDecoration(labelText: 'Message')
),
StoreConnector(
converter: (Store store) =>
(message) => store.dispatch(MessageAction(message: message)),
rebuildOnChange: false,
builder: (_, dispatchMessageAction) =>
OutlineButton(
onPressed: () => dispatchMessageAction(_messageController.text),
child: Text('SEND')
)
),
],
),
),
);
}
```