meta_types_redux 0.1.0

meta_types_redux #

An extension of redux.dart that uses meta types to enforce type safety and implement slick reducer/middlware declarations.

0.0.1 #

  • initial annotations for annotating union, enum, and data classes

example/example.dart

import 'package:meta_types/meta_types.dart';
import 'package:meta_types_redux/meta_types_redux.dart';

part 'example.g.dart';

@DataClass()
abstract class $Counter {
  int get count => 0;
}

// $Counter tells the generator the state to use for the
// reducer and middlwarehandler code should be of type Counter
@Actions($Counter)
@SealedClass()
abstract class $CounterActions {
  int get increment;
  int get decrement;
}

void main() {
  final store = MetaTypesStore<Counter, CounterActions>(
    reducer: myReducer,
    initialState: Counter(),
    metaMiddleware: [myMiddleware],
    syncStream: true,
  );

  store.onChange.listen((state) => print(state.count));

  store.dispatch(CounterActions.incrementFactory(1));
  // increment mw: 1
  // 1
  store.dispatch(CounterActions.incrementFactory(4));
  // increment mw: 4
  // 5
  store.dispatch(CounterActions.decrementFactory(1));
  // decrement mw: 1
  // 4
}

final myReducer = (Counter c, CounterActions a) => a.reduce(
      c,
      increment: _increment,
      decrement: _decrement,
    );

Counter _increment(Counter state, int val) =>
    state.clone(count: state.count + val);

Counter _decrement(Counter state, int val) =>
    state.clone(count: state.count - val);

final myMiddleware = (
  MiddlewareApi<Counter, CounterActions> api,
  MetaNextDispatcher next,
  CounterActions a,
) =>
    a.handleMiddleware(
      api,
      next,
      increment: _incrementHandler,
      decrement: _decrementHandler,
    );

void _incrementHandler(MiddlewareApi<Counter, CounterActions> api,
    MetaNextDispatcher next, int val) {
  print('increment mw: $val');
  next();
}

void _decrementHandler(MiddlewareApi<Counter, CounterActions> api,
    MetaNextDispatcher next, int val) {
  print('decrement mw: $val');
  next();
}

Use this package as a library

1. Depend on it

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


dependencies:
  meta_types_redux: ^0.1.0

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:meta_types_redux/meta_types_redux.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
56
Overall:
Weighted score of the above. [more]
41
Learn more about scoring.

We analyzed this package on Aug 22, 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:meta_types_redux/meta_types_redux.dart.

Health suggestions

Fix lib/meta_types_redux.dart. (-1.49 points)

Analysis of lib/meta_types_redux.dart reported 3 hints:

line 44 col 46: Use = to separate a named parameter from its default value.

line 45 col 35: Use = to separate a named parameter from its default value.

line 46 col 20: Use = to separate a named parameter from its default value.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/davidmarne/dart_meta_types/meta_types_redux was unreachable.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is getting outdated. (-3.84 points)

The package was last published 54 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2-0-0-dev <3.0.0
meta ^1.0.0 1.1.7
meta_types ^0.1.0 0.1.0
redux ^3.0.0 3.0.0
Dev dependencies
build_runner ^0.9.0
meta_types_generator ^0.1.0
meta_types_redux_generator