Skip to content

Commit

Permalink
Use workiva_analysis_options, address lints
Browse files Browse the repository at this point in the history
  • Loading branch information
evanweible-wf committed Nov 10, 2023
1 parent 854ab19 commit 1dbd942
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 848 deletions.
718 changes: 3 additions & 715 deletions analysis_options.yaml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions lib/src/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class Action<T> extends ActionV2<T?> {
/// when a consumer needs to check state changes immediately after invoking an
/// action.
///
class ActionV2<T> extends Object with Disposable implements Function {
class ActionV2<T> extends Object with Disposable {
@override
String get disposableTypeName => 'ActionV2';

List<_ActionListener<T>> _listeners = [];
final _listeners = <_ActionListener<T>>[];

/// Dispatch this [ActionV2] to all listeners. The payload will be passed to
/// each listener's callback.
Expand Down Expand Up @@ -99,11 +99,14 @@ class ActionV2<T> extends Object with Disposable implements Function {
}

@override
// ignore: prefer_void_to_null
Future<Null> onDispose() async {
_listeners.clear();
}

/// Actions are only deemed equivalent if they are the exact same Object
@override
// ignore: hash_and_equals
bool operator ==(Object other) {
return identical(this, other);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/component_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ library w_flux.src.component_client;

import 'package:meta/meta.dart';

import 'package:w_flux/src/action.dart';
import 'package:w_flux/src/component_common.dart';
import 'package:w_flux/src/mixins/batched_redraws.dart';
import 'package:w_flux/src/store.dart';

/// FluxComponents are responsible for rendering application views and turning
/// user interactions and events into [Action]s. FluxComponents can use data
/// user interactions and events into [ActionV2]s. FluxComponents can use data
/// from one or many [Store] instances to define the resulting component.
///
/// This FluxComponent, intended for use on the client, utilizes the
Expand Down
12 changes: 7 additions & 5 deletions lib/src/component_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@ import 'package:meta/meta.dart';
import 'package:react/react.dart' as react;
import 'package:w_common/disposable.dart';

import 'package:w_flux/src/action.dart';
import 'package:w_flux/src/constants.dart' show v3Deprecation;
import 'package:w_flux/src/store.dart';

/// FluxComponents are responsible for rendering application views and turning
/// user interactions and events into [Action]s. FluxComponents can use data
/// user interactions and events into [ActionV2]s. FluxComponents can use data
/// from one or many [Store] instances to define the resulting component.
// ignore: deprecated_member_use
abstract class FluxComponentCommon<ActionsT, StoresT> extends react.Component
with Disposable {
/// The class instance defined by [ActionsT] that holds all [Action]s that
/// The class instance defined by [ActionsT] that holds all [ActionV2]s that
/// this component needs access to.
///
/// There is no strict rule on the [ActionsT] type. Depending on application
/// structure, there may be [Action]s available directly on this object, or
/// structure, there may be [ActionV2]s available directly on this object, or
/// this object may represent a hierarchy of actions.
ActionsT get actions => this.props['actions'] as ActionsT;
ActionsT get actions => props['actions'] as ActionsT;

/// The class instance defined by [StoresT]. This object should either be an
/// instance of [Store] or should provide access to one or more [Store]s.
Expand All @@ -52,7 +54,7 @@ abstract class FluxComponentCommon<ActionsT, StoresT> extends react.Component
/// [StoresT] should be a class that provides access to these multiple stores.
/// Then, you can explicitly select the [Store] instances that should be
/// listened to by overriding [redrawOn].
StoresT get store => this.props['store'] as StoresT;
StoresT get store => props['store'] as StoresT;

@mustCallSuper
@override
Expand Down
3 changes: 2 additions & 1 deletion lib/src/component_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

library w_flux.src.component_server;

import 'package:w_flux/src/action.dart';
import 'package:w_flux/src/component_common.dart';
import 'package:w_flux/src/store.dart';

/// FluxComponents are responsible for rendering application views and turning
/// user interactions and events into [Action]s. FluxComponents can use data
/// user interactions and events into [ActionV2]s. FluxComponents can use data
/// from one or many [Store] instances to define the resulting component.
///
/// This FluxComponent, intended for use on the server, does not depend on
Expand Down
29 changes: 16 additions & 13 deletions lib/src/mixins/batched_redraws.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// ignore_for_file: deprecated_member_use

library w_flux.mixins.batched_redraws;

import 'dart:async';
import 'dart:html';

import 'package:react/react.dart' as react;

class _RedrawScheduler implements Function {
Map<BatchedRedraws, List<Function>> _components =
<BatchedRedraws, List<Function>>{};
import 'package:w_flux/src/component_client.dart';

class _RedrawScheduler {
final _components = <BatchedRedraws, List<Function>>{};

void call(BatchedRedraws component, [callback()?]) {
void call(BatchedRedraws component, [Function()? callback]) {
if (_components.isEmpty) {
_tick();
}
Expand All @@ -23,11 +26,11 @@ class _RedrawScheduler implements Function {
await window.animationFrame;

// Making a copy of `_components` so we don't iterate over the map while it's potentially being mutated.
var entries = _components.entries.toList();
final entries = _components.entries.toList();
_components.clear();
for (var entry in entries) {
var component = entry.key;
var callbacks = entry.value;
for (final entry in entries) {
final component = entry.key;
final callbacks = entry.value;
// Skip if the component doesn't want to batch redraw
if (!component.shouldBatchRedraw) {
continue;
Expand All @@ -37,9 +40,9 @@ class _RedrawScheduler implements Function {

if (callbacks.isNotEmpty) {
chainedCallbacks = () {
callbacks.forEach((callback) {
for (final callback in callbacks) {
callback();
});
}
};
}

Expand All @@ -53,8 +56,8 @@ class _RedrawScheduler implements Function {

_RedrawScheduler _scheduleRedraw = _RedrawScheduler();

/// A mixin that overrides the [Component.redraw] method of a React
/// [Component] (including a [FluxComponent]) and prevents the component
/// A mixin that overrides the [react.Component.redraw] method of a React
/// [react.Component] (including a [FluxComponent]) and prevents the component
/// from being redrawn more than once per animation frame.
///
/// Example:
Expand All @@ -67,5 +70,5 @@ _RedrawScheduler _scheduleRedraw = _RedrawScheduler();
class BatchedRedraws {
bool shouldBatchRedraw = true;

void redraw([callback()?]) => _scheduleRedraw(this, callback);
void redraw([Function()? callback]) => _scheduleRedraw(this, callback);
}
11 changes: 6 additions & 5 deletions lib/src/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef StoreHandler = Function(Store event);
/// listened to. Whenever a `Store`'s data is mutated, the `trigger` method is
/// used to tell all registered listeners that updated data is available.
///
/// In a typical application using `w_flux`, a [FluxComponent] listens to
/// In a typical application using `w_flux`, a `FluxComponent` listens to
/// `Store`s, triggering re-rendering of the UI elements based on the updated
/// `Store` data.
class Store extends Stream<Store> with Disposable {
Expand Down Expand Up @@ -95,7 +95,7 @@ class Store extends Stream<Store> with Disposable {
/// needed.
@override
StreamSubscription<Store> listen(StoreHandler? onData,
{Function? onError, void onDone()?, bool? cancelOnError}) {
{Function? onError, void Function()? onDone, bool? cancelOnError}) {
if (isDisposed) {
throw StateError('Store of type $runtimeType has been disposed');
}
Expand Down Expand Up @@ -140,8 +140,9 @@ class Store extends Stream<Store> with Disposable {
/// If the `Store` has been disposed, this method throws a [StateError].
/// Deprecated: 2.9.5
/// To be removed: 3.0.0
@deprecated
triggerOnAction(ActionV2 action, [void onAction(payload)?]) {
@Deprecated('Use triggerOnActionV2 instead')
// ignore: always_declare_return_types, type_annotate_public_apis
triggerOnAction(ActionV2 action, [void Function(dynamic payload)? onAction]) {
triggerOnActionV2(action, onAction);
}

Expand All @@ -154,7 +155,7 @@ class Store extends Stream<Store> with Disposable {
///
/// If the `Store` has been disposed, this method throws a [StateError].
void triggerOnActionV2<T>(ActionV2<T> action,
[FutureOr<dynamic> onAction(T payload)?]) {
[FutureOr<dynamic> Function(T payload)? onAction]) {
if (isOrWillBeDisposed) {
throw StateError('Store of type $runtimeType has been disposed');
}
Expand Down
12 changes: 8 additions & 4 deletions lib/w_flux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
// limitations under the License.

/// The w_flux library implements a uni-directional data flow pattern comprised
/// of [Action]s, [Store]s, and [FluxComponent]s.
/// of [ActionV2]s, [Store]s, and [FluxComponent]s.
///
/// - [Action]s initiate mutation of app data that resides in [Store]s.
/// - [ActionV2]s initiate mutation of app data that resides in [Store]s.
/// - Data mutations within [Store]s trigger re-rendering of app view (defined
/// in [FluxComponent]s).
/// - [FluxComponent]s dispatch [Action]s in response to user interaction.
/// - [FluxComponent]s dispatch [ActionV2]s in response to user interaction.
library w_flux;

import 'src/action.dart';
import 'src/component_client.dart';
import 'src/store.dart';

export 'src/action.dart';
export 'src/component_client.dart';
export 'src/store.dart';
export 'src/mixins/batched_redraws.dart';
export 'src/store.dart';
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ dev_dependencies:
build_runner: ^2.0.0
build_test: ^2.1.3
build_web_compilers: ^3.0.0
dart_dev: ^4.0.0
dart_dev: ^4.1.0
dependency_validator: ^3.0.0
test: ^1.18.2
test: ^1.18.2
workiva_analysis_options: ^1.3.0

dependency_overrides:
react:
Expand Down
Loading

0 comments on commit 1dbd942

Please sign in to comment.