Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve and fix public docs #78

Merged
merged 1 commit into from Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/equatable.dart
@@ -1,3 +1,5 @@
/// A mixin that helps implement equality without needing to explicitly override
/// `==` operators or `hashCode`s.
library equatable;

export './src/equatable.dart';
Expand Down
28 changes: 20 additions & 8 deletions lib/src/equatable.dart
Expand Up @@ -3,7 +3,7 @@ import 'package:meta/meta.dart';
import './equatable_config.dart';
import './equatable_utils.dart';

/// A base class to facilitate [operator==] and [hashCode] overrides.
/// A base class to facilitate [operator ==] and [hashCode] overrides.
///
/// ```dart
/// class ConstTest extends Equatable {
Expand All @@ -17,19 +17,31 @@ import './equatable_utils.dart';
/// ```
@immutable
abstract class Equatable {
/// The [List] of `props` (properties) which will be used to determine whether
/// two [Equatables] are equal.
/// {@template equatable_props}
/// The list of properies that will be used to determine whether
/// two [Equatable]s are equal.
/// {@endtemplate}
List<Object> get props;

/// If the value is [true], the `toString` method will be overrided to print
/// the equatable `props`.
/// {@template equatable_stringify}
/// If set to `true`, the [toString] method will be overridden to output
/// this [Equatable]'s [props].
///
/// A global default value for [stringify] can be set using
/// [EquatableConfig.stringify].
///
/// If this [Equatable]'s [stringify] is set to null, the value of
/// [EquatableConfig.stringify] will be used instead. That value deafults to
/// `false`.
/// {@endtemplate}
// ignore: avoid_returning_null
bool get stringify => null;

/// A class that helps implement equality
/// without needing to explicitly override == and [hashCode].
/// Equatables override their own `==` operator and [hashCode] based on their
/// `props`.
/// without needing to explicitly override [operator ==] and [hashCode].
///
/// [Equatable]s override their own [operator ==] and [hashCode] based on
/// their [props].
const Equatable();

@override
Expand Down
17 changes: 14 additions & 3 deletions lib/src/equatable_config.dart
@@ -1,10 +1,21 @@
// ignore: avoid_classes_with_only_static_members
/// Global [Equatable] configuration settings
import 'equatable.dart';

// ignore_for_file: avoid_classes_with_only_static_members

/// The default configurion for all [Equatable]s.
///
/// Currently, this config class only supports setting a default value for
/// [stringify].
///
/// See also:
/// * [Equatable.stringify]
class EquatableConfig {
/// Global [stringify] setting for all [Equatable] instances.
///
/// If [stringify] is overridden for a particular [Equatable] instance,
/// then the local [stringify] value takes precedence
/// over `EquatableConfig.stringify`.
/// over [EquatableConfig.stringify].
///
/// This value defaults to false.
static bool stringify = false;
}
14 changes: 6 additions & 8 deletions lib/src/equatable_mixin.dart
@@ -1,18 +1,16 @@
import 'equatable_config.dart';
import 'equatable_utils.dart';

/// You must define the [EquatableMixin] on the class
/// which you want to make Equatable.
/// A mixin that helps implement equality
/// without needing to explicitly override [operator ==] and [hashCode].
///
/// [EquatableMixin] does the override of the `==` operator as well as
/// `hashCode`.
/// Like with extending [Equatable], the [EquatableMixin] overrides the
/// [operator ==] as well as the [hashCode] based on the provided [props].
mixin EquatableMixin {
/// The [List] of `props` (properties) which will be used to determine whether
/// two [Equatables] are equal.
/// {@macro equatable_props}
List<Object> get props;

/// If the value is [true], the `toString` method will be overrided to print
/// the equatable `props`.
/// {@macro equatable_stringify}
bool get stringify => false;

@override
Expand Down