Skip to content

Commit

Permalink
refactor(consumed_thing): pass affordances to _getClientFor
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Mar 11, 2022
1 parent 881ace9 commit 99a5281
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/src/core/consumed_thing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ class ConsumedThing implements scripting_api.ConsumedThing {
}
}

_ClientAndForm _getClientFor(List<Form> forms, OperationType operationType,
_AffordanceType affordanceType, InteractionOptions? options) {
_ClientAndForm _getClientFor(
List<Form> forms,
OperationType operationType,
_AffordanceType affordanceType,
InteractionOptions? options,
InteractionAffordance interactionAffordance) {
if (forms.isEmpty) {
throw ArgumentError(
'ConsumedThing "$title" has no links for this interaction');
Expand Down Expand Up @@ -150,8 +154,12 @@ class ConsumedThing implements scripting_api.ConsumedThing {
'ConsumedThing $title does not have property $propertyName');
}

final clientAndForm = _getClientFor(property.augmentedForms,
OperationType.readproperty, _AffordanceType.property, options);
final clientAndForm = _getClientFor(
property.augmentedForms,
OperationType.readproperty,
_AffordanceType.property,
options,
property);

final form = clientAndForm.form;
final client = clientAndForm.client;
Expand All @@ -171,8 +179,12 @@ class ConsumedThing implements scripting_api.ConsumedThing {
'ConsumedThing $title does not have property $propertyName');
}

final clientAndForm = _getClientFor(property.augmentedForms,
OperationType.writeproperty, _AffordanceType.property, options);
final clientAndForm = _getClientFor(
property.augmentedForms,
OperationType.writeproperty,
_AffordanceType.property,
options,
property);

final form = clientAndForm.form; // TODO(JKRhb): Handle URI variables
final client = clientAndForm.client;
Expand All @@ -192,7 +204,7 @@ class ConsumedThing implements scripting_api.ConsumedThing {
}

final clientAndForm = _getClientFor(action.augmentedForms,
OperationType.invokeaction, _AffordanceType.action, options);
OperationType.invokeaction, _AffordanceType.action, options, action);

final form = clientAndForm.form; // TODO(JKRhb): Handle URI variables
final client = clientAndForm.client;
Expand Down Expand Up @@ -272,8 +284,8 @@ class ConsumedThing implements scripting_api.ConsumedThing {
subscriptions = _subscribedEvents;
}

final clientAndForm = _getClientFor(
affordance.augmentedForms, operationType, affordanceType, options);
final clientAndForm = _getClientFor(affordance.augmentedForms,
operationType, affordanceType, options, affordance);

final form = clientAndForm.form; // TODO(JKRhb): Handle URI variables
final client = clientAndForm.client;
Expand Down

0 comments on commit 99a5281

Please sign in to comment.