dart_dva 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 10

dart_dva #

pub package

Dart版本的轻量Dva。

简化Redux使用流程,将你从Action的命名和创建的繁琐步骤中解救出来。

并且提供Action异步方案。

该项目目前还在开发阶段。

使用方法 #

import 'dart:async';

import 'package:meta/meta.dart';

import 'package:dart_dva/dart_dva.dart';

class UserInfo {
  String name;
  int id;
  UserInfo({@required this.id, this.name = 'init'});
}

class LoginState {
  bool loading;
  UserInfo info;
  LoginState({this.loading = false, this.info});

  LoginState copyWith(payload) {
    return LoginState(
      loading:
          payload.containsKey('loading') ? payload['loading'] : this.loading,
      info: payload.containsKey('info') ? payload['info'] : this.info,
    );
  }
}

Future<UserInfo> asyncInfo() async {
  final info = await new Future.delayed(new Duration(seconds: 3), () {
    return UserInfo(id: 3, name: 'newname_3');
  });
  return info;
}

void main() {
  final loginModel = DvaModel<LoginState>(
  namespace: 'login', 
  state: LoginState(), 
  effects: [
    DvaEffect(
        type: 'getUserinfo',
        handler: (Store store, DvaAction action, DvaUtils utils) async {
          final newinfo = await asyncInfo();
          utils.put(DvaAction(
              type: 'save', payload: {'info': newinfo, 'loading': true}));
        })
  ], reducers: [
    DvaReducer<LoginState>(
        type: 'save',
        handler: (LoginState state, DvaAction action) {
          return state.copyWith(action.payload);
        }),
  ]);

  final dva = Dva.create(models: [loginModel]);
  final store = dva.store;

  // store.dispatch(DvaAction(type: 'login/save', payload: {'loading': true, 'info': 2}));
  dva.dispatch(DvaAction(type: 'login/getUserinfo')).then((_) {
    print(store.state['login'].info.name);
    dva.dispatch(DvaAction(
        type: 'login/save',
        payload: {'info': UserInfo(id: 5, name: 'finalname')})).then((_) {
          print(store.state['login'].info.name);
        });
  });
}

[0.0.1] - February 20th, 2019

  • 初始化项目,简化Redux使用流程并提供异步解决方案。

example/main.dart

import 'dart:async';

import 'package:meta/meta.dart';

import 'package:dart_dva/dart_dva.dart';

class UserInfo {
  String name;
  int id;
  UserInfo({@required this.id, this.name = 'init'});
}

class LoginState {
  bool loading;
  UserInfo info;
  LoginState({this.loading = false, this.info});

  LoginState copyWith(payload) {
    return LoginState(
      loading:
          payload.containsKey('loading') ? payload['loading'] : this.loading,
      info: payload.containsKey('info') ? payload['info'] : this.info,
    );
  }
}

Future<UserInfo> asyncInfo() async {
  final info = await new Future.delayed(new Duration(seconds: 3), () {
    return UserInfo(id: 3, name: 'newname_3');
  });
  return info;
}

void main() {
  final loginModel = DvaModel<LoginState>(
  namespace: 'login', 
  state: LoginState(), 
  effects: [
    DvaEffect(
        type: 'getUserinfo',
        handler: (Store store, DvaAction action, DvaUtils utils) async {
          final newinfo = await asyncInfo();
          utils.put(DvaAction(
              type: 'save', payload: {'info': newinfo, 'loading': true}));
        })
  ], reducers: [
    DvaReducer<LoginState>(
        type: 'save',
        handler: (LoginState state, DvaAction action) {
          return state.copyWith(action.payload);
        }),
  ]);

  final dva = Dva.create(models: [loginModel]);
  final store = dva.store;

  // store.dispatch(DvaAction(type: 'login/save', payload: {'loading': true, 'info': 2}));
  dva.dispatch(DvaAction(type: 'login/getUserinfo')).then((_) {
    print(store.state['login'].info.name);
    dva.dispatch(DvaAction(
        type: 'login/save',
        payload: {'info': UserInfo(id: 5, name: 'finalname')})).then((_) {
          print(store.state['login'].info.name);
        });
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_dva: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_dva/dart_dva.dart';
  
Version Uploaded Documentation Archive
0.0.1 Feb 20, 2019 Go to the documentation of dart_dva 0.0.1 Download dart_dva 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
10
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms:

Error(s) prevent platform classification:

Error(s) in lib/dart_dva.dart: Target of URI doesn't exist: 'package:meta/meta.dart'.

Health issues and suggestions

Fix lib/dart_dva.dart. (-99.68 points)

Analysis of lib/dart_dva.dart failed with 20 errors, including:

line 5 col 8: Target of URI doesn't exist: 'package:meta/meta.dart'.

line 34 col 14: Undefined name 'required' used as an annotation.

line 43 col 15: Undefined name 'required' used as an annotation.

line 43 col 36: Undefined name 'required' used as an annotation.

line 55 col 13: Undefined name 'required' used as an annotation.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Error(s) in lib/dart_dva.dart: Target of URI doesn't exist: 'package:meta/meta.dart'.

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 pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <3.0.0
redux >=3.0.0 <4.0.0 3.0.0
Dev dependencies
test >=0.12.24+2 <2.0.0