Skip to content

Commit

Permalink
nnbd - phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmarne-wf committed Feb 5, 2021
1 parent 33bef12 commit afb6c90
Show file tree
Hide file tree
Showing 22 changed files with 187 additions and 319 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: dart
dart: stable
dart: [dev]
sudo: required
addons:
chrome: stable
Expand Down
4 changes: 2 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ builders:
target: ":built_redux"
import: "package:built_redux/builder.dart"
builder_factories: ["builtRedux"]
build_extensions: {".dart": [".built_redux.g.part"]}
build_extensions: { ".dart": [".built_redux.g.part"] }
auto_apply: dependents
build_to: cache
applies_builders: ["source_gen|combining_builder"]
applies_builders: ["source_gen|combining_builder"]
32 changes: 16 additions & 16 deletions example/example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/built_redux_test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import 'built_redux.dart';
/// It takes all of the same optional params as expectAsync.
void expectDispatched<T>(
ActionDispatcher<T> actionDispatcher, {
void verifier(Action<T> action),
@deprecated void verfier(Action<T> action),
void Function(Action<T> action)? verifier,
@deprecated void Function(Action<T> action)? verfier,
int count = 1,
int max = 0,
String id,
String reason,
String? id,
String? reason,
}) {
actionDispatcher.setDispatcher(expectAsync1((Action<dynamic> action) {
if (verifier != null) verifier(action as Action<T>);
Expand Down
2 changes: 1 addition & 1 deletion lib/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ActionsClass _actionsClassFromElement(ClassElement element) => ActionsClass(
Iterable<ComposedActionClass> _composedActionClasses(ClassElement element) =>
element.fields
.where((f) => _isReduxActions(f.type.element))
.map((f) => ComposedActionClass(f.name, f.type.name));
.map((f) => ComposedActionClass(f.name, f.type.element.name));

Iterable<Action> _actionsFromElement(ClassElement element) => element.fields
.where(_isActionDispatcher)
Expand Down
43 changes: 41 additions & 2 deletions lib/src/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,51 @@ class Action<Payload> {
/// The actions payload.
final Payload payload;

// factory Action(name, payload) => NullableAction(name, payload);
Action(this.name, this.payload);

@override
String toString() => 'Action {\n name: $name,\n payload: $payload,\n}';
}

/// [Action] is the object passed to your reducer to signify the state change that needs to take place.
/// Action [name]s should always be unique. Uniqeness is guarenteed when using ReduxActions.
// class NonNullableAction<Payload> implements Action<Payload?> {
// /// A unique action name.
// final String _name;

// /// The actions payload.
// final Payload _payload;

// String get name => _name;

// Payload get payload => _payload;

// NonNullableAction(this._name, this._payload);

// @override
// String toString() => 'Action {\n name: $name,\n payload: $payload,\n}';
// }

// /// [Action] is the object passed to your reducer to signify the state change that needs to take place.
// /// Action [name]s should always be unique. Uniqeness is guarenteed when using ReduxActions.
// class NullableAction<Payload> implements Action<Payload> {
// /// A unique action name.
// final String _name;

// /// The actions payload.
// final Payload? _payload;

// String get name => _name;

// Payload? get payload => _payload;

// NullableAction(this._name, this._payload);

// @override
// String toString() => 'Action {\n name: $name,\n payload: $payload,\n}';
// }

// Dispatches an action to the store
typedef Dispatcher<P> = void Function(Action<P> action);

Expand All @@ -26,12 +65,12 @@ typedef Dispatcher<P> = void Function(Action<P> action);
/// store.actions.increment(3);
/// ```
class ActionDispatcher<P> {
Dispatcher _dispatcher;
late Dispatcher _dispatcher;
final String _name;

String get name => _name;

void call([P payload]) => _dispatcher(Action<P>(_name, payload));
void call(P payload) => _dispatcher(Action<P>(_name, payload));

ActionDispatcher(this._name);

Expand Down
6 changes: 2 additions & 4 deletions lib/src/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Store<
_stateController = StreamController.broadcast();

// the current state
State _state;
Actions _actions;
late State _state;
late final Actions _actions;

Store(
Reducer<State, StateBuilder, dynamic> reducer,
Expand Down Expand Up @@ -70,8 +70,6 @@ class Store<
/// [dispose] removes closes both the dispatch and subscription stream
Future<Null> dispose() async {
await _stateController.close();
_state = null;
_actions = null;
}

/// [replaceState] replaces the state of your store.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/store_change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class StoreChangeHandlerBuilder<
StateBuilder extends Builder<State, StateBuilder>,
Actions extends ReduxActions> {
final _map = Map<String, StoreChangeHandler<dynamic, State, StateBuilder>>();
StreamSubscription<StoreChange<State, StateBuilder, dynamic>> _subscription;
late StreamSubscription<StoreChange<State, StateBuilder, dynamic>>
_subscription;

/// Registers [handler] function to the given [actionName]
void add<Payload>(ActionName<Payload> actionName,
Expand Down
19 changes: 9 additions & 10 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
name: built_redux
version: 7.5.11
description:
A state management library written in dart that enforces immutability
version: 8.0.0-nullsafety.0
description: A state management library written in dart that enforces immutability
homepage: https://github.com/davidmarne/built_redux
dependencies:
analyzer: '>=0.33.0 <0.40.0'
analyzer: ">=0.40.0 <0.41.0"
build: ^1.2.2
built_collection: ^4.3.0
built_value: '>=6.8.2 <8.0.0'
built_collection: ^5.0.0-nullsafety.0
built_value: ^8.0.0-nullsafety.0
source_gen: ^0.9.4+6
test: ^1.9.1
test: ^1.16.0-nullsafety

dev_dependencies:
build_runner: ^1.7.1
build_test: ^0.10.11
built_value_generator: ^7.0.0
build_test: ^1.2.0
built_value_generator: ^8.0.0-nullsafety.0
build_web_compilers: ^2.7.1
workiva_analysis_options: ^1.0.0

environment:
sdk: '>=2.4.0 <3.0.0'
sdk: ">=2.12.0-0 <3.0.0"
2 changes: 1 addition & 1 deletion test/unit/action_generics_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Reducer<ActionGenerics, ActionGenericsBuilder, dynamic>
..add<Map<String, List<int>>>(
ActionGenericsActionsNames.mapStringToListIntAction,
(s, a, b) =>
b.count += a.payload['k'].fold<int>(0, (c, n) => c + n)))
b.count += a.payload['k']??.fold<int>(0, (c, n) => c + n)))
.build();

NextActionHandler thunkMiddleware(
Expand Down
Loading

0 comments on commit afb6c90

Please sign in to comment.