Skip to content

Commit

Permalink
more documentation comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lohanidamodar committed Mar 11, 2024
1 parent c30917c commit d2bd755
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Improve library namings
- Fixes for reset methods
- Add doc comments
- Support context while resetting cached resources

## 0.1.0
Expand Down
4 changes: 2 additions & 2 deletions lib/src/di.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'resource_callback.dart';

/// Dependency injection
///
///
/// Simple and easy dependency injection
/// for your Dart applications.
///
///
/// Part of Utopia Dart ecosystem,
/// but can be used independently.
class DI {
Expand Down
42 changes: 23 additions & 19 deletions lib/src/hook.dart
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
import 'param.dart';
import 'validators/validator.dart';

/// Utopia Hook, extended by various other
/// utopia libraries.
///
/// A hook provides an action to be executed
class Hook {
/// Description
String description = '';
List<String> _groups = [];
static int counter = 0;
static int _counter = 0;
final Map<String, Param> _params = {};
final List<String> _injections = [];
late int order;
late Function _action;

final List<String> _argsOrder = [];

/// Order of arguments
List<String> get argsOrder => _argsOrder;

/// Injections
List<String> get injections => _injections;

/// Parameters
Map<String, Param> get params => _params;

/// Get groups
List<String> getGroups() => _groups;

/// Get action
Function getAction() => _action;

Hook() {
Hook.counter++;
order = counter;
Hook._counter++;
order = _counter;
_action = () {};
}

/// Hooks action to be executed
/// when executing hook
Hook action(Function action) {
_action = action;
return this;
}

/// Set hook description
Hook desc(String description) {
this.description = description;
return this;
}

/// Set hook groups
Hook groups(List<String> groups) {
_groups = groups;
return this;
}

/// Inject dependencies
Hook inject(String injection) {
if (_injections.contains(injection)) {
throw Exception("Injection already declared for $injection");
Expand All @@ -48,6 +67,7 @@ class Hook {
return this;
}

/// Set hook param
Hook param({
required String key,
dynamic defaultValue,
Expand All @@ -66,19 +86,3 @@ class Hook {
return this;
}
}

class Param {
final dynamic defaultValue;
final Validator? validator;
final String description;
final dynamic value;
final bool optional;

Param({
required this.defaultValue,
required this.validator,
required this.description,
required this.value,
required this.optional,
});
}
18 changes: 18 additions & 0 deletions lib/src/param.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'validators/validator.dart';

/// Param
class Param {
final dynamic defaultValue;
final Validator? validator;
final String description;
final dynamic value;
final bool optional;

Param({
required this.defaultValue,
required this.validator,
required this.description,
required this.value,
required this.optional,
});
}
4 changes: 2 additions & 2 deletions lib/src/resource_callback.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/// Resource callback
class ResourceCallback {
final String name;
final List<String> injections;
Expand All @@ -15,4 +15,4 @@ class ResourceCallback {
ResourceCallback copyWith({bool? reset}) {
return ResourceCallback(name, injections, callback, reset: reset ?? false);
}
}
}
8 changes: 8 additions & 0 deletions lib/src/validators/allow_list.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import 'validator.dart';

/// Allow list validator
class AllowList<T> extends Validator {
final List<T> _list;

/// List of allowed values
List<T> get list => _list;

AllowList(this._list, {bool strict = false});

/// Error description
@override
String getDescription() {
return 'Value must of one of (${_list.join(", ")})';
}

/// Type of list
@override
String getType() {
return T.toString();
}

/// Is array
@override
bool isArray() {
return false;
}

/// Is valid
/// Returns true if the given value
/// is valid or false otherwise
@override
bool isValid(value) {
if (value is List) return false;
Expand Down

0 comments on commit d2bd755

Please sign in to comment.