osam 2.1.8

  • Readme
  • Changelog
  • Example
  • Installing
  • new50


GitHub Logo

Introduction #

Osam - it is state management library inspired by redux, bloc and SOLID principles. If your are familiar with functional programming you should probably use built_redux but here is a lot of benefits then Bloc or Build_redux.

Glossary #

BaseState #

it is mutable domain element witch contains data and state methods. BaseState streaming it self every time, when you calling methods by Event. Also BaseState can stream every property if you listen it. Cool feature: property streams and state streams do NOT stream it self if previous state is equal

Event #

Here is two types of this element. First - Event.modify, this is Event witch stores a reducer - just a lambda to call method of the state. Like:

(state,_) => state..increment();

And Bundle to send a something for method:

(state, bundle) => state..increment(bundle);

You can specify a type for your event to catch event in middleware, enum is Good for this case. Second - Event.sideEffect. Try to guess... it for side effects. It is contains a bundle and type, to catch it in middleware to.

Middleware #

Middleware it is Domain element too, with you business logic conditions. Every event is throwing inside every middleware. That means that you can send another event if you catch target event. Example:

if (event.type == EventType.increment) {
            event: Event.modify(
                reducer: (state, _) => state..increment(1), type: EventType.increment));
    return nextEvent(true);

Notice: return nextEvent with true if you want other middlewares can catch your target event. Or false if you wouldn't.

Store #

Domain element too. Stores your domain tree of states, starting from your appState entry point. and stack of middlewares.

Rules #

Osam - it is about strong rules. Interfaces and inheritance of the domain and presentation layer is very strong. In my opinion it is very necessary if you are working in team. BaseState stream it self only if you dispatching Events to Store. Your Middlewares, BaseStates and Presenters working, only if you extending this library elements. To understand how everything works, I would recommend look at examples.

Presentation #

If you familiar with a provider or inherited widget, you will not have a problems to use it. This is very simple to provide Store for every widgets inside you widget tree. But it is automatically provided for PresenterProviders.

Store and StoreProvider #

In main function create a instance of Store with your state and middlewares. Put store and your entry point widget in to Store provider

 final store = Store(AppState(), middleWares: []);

  Widget build(BuildContext context) {
    return MaterialApp(
      home: StoreProvider(
        child: MyHomePage(),
        store: store,

Presenter and PresenterProvider #

Well, good practices it is make you ui is dump as possible. And here coming the Presenter. Presenter is good for send events, providing streams and initial data for your widgets. To specify presenter for you widget just use PresenterProvider. Put inside it you widget as a child and instance of Presenter.

PresenterProvider<Store<AppState>, ExamplePresenter>(
        presenter: ExamplePresenter(),
        child: Button(),

Get presenter by using context it is very easy:

final presenter = PresenterProvider.of<ExamplePresenter>(context);

Example of presenter:

class ExamplePresenter<S extends Store<AppState>> extends Presenter<S> {
  StreamSubscription propertySub;
  StreamController<int> modelBroadcaster;

  void init() {
    modelBroadcaster = StreamController<int>();
    store.nextState(store.state).listen((data) {});

  void increment() =>
      store.dispatchEvent(event: Event.modify(reducer: (state, _) => state..increment(1)));

  List<int> get initialData => store.state.count;

  Stream<List<int>> get stream => store.state.propertyStream<List<int>>((state) => state.count);

  void dispose() {

Conclusion #

Well, I hope this library is useful for you. Here you can see examples, send your apps in github to fill this list =) Thanks! : https://github.com/Renesanse/popular_news https://github.com/Renesanse/osam/tree/master/example

[2.0.1] - 17 nov 2019 16.59

*0.0.1 start osam ent

*0.0.2 edited event

*0.0.5 edited property stream

*1.0.0 refactored middleware

*1.1.1 edited example

*1.2.0 property stream to mapper

*1.3.0 added natty event

*1.3.4 edited presenter

*1.3.5 edited streams for type safety

*2.0.1 added null safety calls


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:

  osam: ^2.1.8

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support 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:osam/osam.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/domain/state/base_state.dart.

Run flutter format to format lib/domain/state/base_state.dart.

Format lib/domain/store/store.dart.

Run flutter format to format lib/domain/store/store.dart.

Format lib/presentation/presenter.dart.

Run flutter format to format lib/presentation/presenter.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/presentation/presenter_provider.dart (Run flutter format to format lib/presentation/presenter_provider.dart.)
  • lib/presentation/store_provider.dart (Run flutter format to format lib/presentation/store_provider.dart.)
  • lib/util/event.dart (Run flutter format to format lib/util/event.dart.)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
equatable ^0.6.1 0.6.1
flutter 0.0.0
provider ^3.1.0+1 3.1.0+1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies