Skip to content

Commit

Permalink
Fixed action parsing and imports, added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleysin committed Nov 30, 2024
1 parent df66ac8 commit 77eef06
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/src/driver_api/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class LocalAction extends ServerAction {

factory LocalAction.fromJson(Map<String, dynamic> json) {
return LocalAction(
event: ServerEvent.parseEvent(json["event"]),
event: ServerEvent.parseEvent(json["payload"]),
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/src/driver_api/event.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import 'package:duit_kernel/src/driver_api/parser.dart';

/// The [ServerEvent] class represents an event that was sent by the server.
///
/// The concrete event types are defined in sub-classes of [ServerEvent].
///
/// The [ServerEvent] class provides a static [parse] method for parsing a JSON map
/// into a concrete event object.
base class ServerEvent {
static late final Parser<ServerEvent> _eventParser;

Expand Down
6 changes: 6 additions & 0 deletions lib/src/driver_api/parser.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/// A base interface for parsers in the DUIT library.
///
/// This interface defines a single method, `parse`, which takes in a JSON object
/// and returns a parsed object of type `T`. This interface is used to define
/// specific parsers for different types of data, such as UI elements, attributes,
/// and scripts.
abstract interface class Parser<T> {
T parse(Map<String, dynamic> json);
}
6 changes: 5 additions & 1 deletion lib/src/driver_api/server_action_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import 'package:duit_kernel/src/driver_api/dependency.dart';
import 'package:duit_kernel/src/driver_api/http_meta.dart';
import 'package:duit_kernel/src/driver_api/script_def.dart';

/// The [ServerActionJsonView] class is a view over a JSON map representing an action.
///
/// The [ServerActionJsonView] class provides a convenient interface for accessing the properties of an
/// action represented as a JSON map. It's used to parse the JSON map into a concrete action object.
extension type ServerActionJsonView(Map<String, dynamic> json) {
Iterable<ActionDependency> get dependsOn {
final hasProperty = json.containsKey("dependsOn");
Expand Down Expand Up @@ -62,4 +66,4 @@ extension type ServerActionJsonView(Map<String, dynamic> json) {
return 0;
}
}
}
}
2 changes: 1 addition & 1 deletion lib/src/driver_api/ui_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:ui';

import '../index.dart';
import 'package:duit_kernel/duit_kernel.dart';

/// Base class for ViewController objects.
///
Expand Down
23 changes: 21 additions & 2 deletions lib/src/ui/tree_element.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import 'package:duit_kernel/duit_kernel.dart';
import 'package:flutter/widgets.dart';

import '../index.dart';

/// An abstract base class representing an entry in the DUIT element tree.
///
/// The `ElementTreeEntry` class serves as the foundational class for elements within
/// the DUIT element tree structure. It maintains essential properties such as the type,
/// ID, and control state of the element, as well as optional attributes and a view controller
/// for managing UI state and interactions.
///
/// Type parameter:
/// - [T]: The type of the data associated with the `UIElementController` and `ViewAttribute`.
///
/// Properties:
/// - [type]: A string representing the type of the DUIT element.
/// - [id]: A unique identifier for the DUIT element.
/// - [controlled]: A boolean indicating whether the DUIT element is controlled.
/// - [tag]: An optional tag for the DUIT element, which can be used for additional identification.
/// - [viewController]: An optional UI element controller for handling UI-specific logic.
/// - [attributes]: Optional view attributes associated with the DUIT element.
///
/// Methods:
/// - [renderView]: Abstract method that must be implemented to render the element as a widget.
abstract base class ElementTreeEntry<T> {
/// The type of the DUIT element.
final String type, id;
Expand Down

0 comments on commit 77eef06

Please sign in to comment.