-
Notifications
You must be signed in to change notification settings - Fork 58
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FED-681: Add integration docs #800
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.... Im second guessing these changes and kinda thinking maybe we just have a simple section that is a bit more to the point...
Integration With DevTools
In order to display the properties of Dart based Action
s and State
in the DevTools they must implement a toJson
method.
toJson
can be manually added to the classes, or added with the help of something like the json_serializable package.
State Example:
class FooState {
bool foo = true;
Map<string, dynamic> toJson() => {'foo': foo};
}
When converted, the result of the toJson
will be used to represent the entire state.
{
"foo": true
}
Action Example:
class FooAction {
bool foo = false;
Map<string, dynamic> toJson() => {'foo': foo};
}
When converted, the Class name will be the type
property and toJson
will become the payload
property.
{
"type": "FooAction",
"payload": {
"foo": false
}
}
For more encoding details check out the redux_remote_devtools package.
|
||
To be able to view and interact with your custom store within the Redux Devtools, your state and actions need to be | ||
serializable. This can be implemented manually or with the help of the [json_serializable](https://pub.dev/packages/json_serializable) library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serializable. This can be implemented manually or with the help of the [json_serializable](https://pub.dev/packages/json_serializable) library. | |
serializable. This can be implemented manually via a `toJson` method or with the help of the [json_serializable](https://pub.dev/packages/json_serializable) library. |
___Encoding Actions and State___ | ||
|
||
In the Javascript world, Redux follows a convention that your redux state is a plain Javascript Object, and actions are also Javascript objects that have a type property. The JS Redux Devtools expect this. However, Redux.dart tries to take advantage of the strong typing available in Dart. To make Redux.dart work with the JS devtools, we need to convert actions and state instances to JSON before sending. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Javascript world, Redux follows a convention that your redux state is a plain Javascript Object, and actions are also Javascript objects that have a type property. The JS Redux Devtools expect this. However, Redux.dart tries to take advantage of the strong typing available in Dart. To make Redux.dart work with the JS devtools, we need to convert actions and state instances to JSON before sending. | |
The Redux Devtools anticipate JS Objects. However, because Redux.dart uses Dart's strong typing, which doesn't map 1 to 1 with JS, so in order to see Dart properties in the DevTools, we need to convert the actions and state to JSON. To do this `jsonEncode` is used before sending to the DevTools, it defaults to calling `.toJson()` on the object. |
|
||
___Enconding Strategy for Actions___ | ||
We use the class name as the action type for class based actions. For enum typed actions, we use the value of the action. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the class name as the action type for class based actions. For enum typed actions, we use the value of the action. For example: | |
The class name automatically gets used as the Action's `type` for class based actions. For enum typed actions, the value of the Action is used. For example: |
attach this JSON data as a payload property. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also want to send the action properties over to devtools. To do this, we attempt to `jsonEncode` the entire Action, and | |
attach this JSON data as a payload property. For example: | |
To include the Action's properties in the devtools `jsonEncode` is performed, and the resulting JSON is attached as the `payload` property. For example: |
{ | ||
"type": "ClassAction", | ||
"payload": { | ||
"someValue": 5 // or whatever someValue was set to | ||
}, | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```json lines | |
{ | |
"type": "ClassAction", | |
"payload": { | |
"someValue": 5 // or whatever someValue was set to | |
}, | |
} | |
``` | |
```json lines | |
{ | |
"type": "ClassAction", | |
"payload": { | |
"someValue": "whatever someValue was set to" | |
}, | |
} |
int someValue; | ||
|
||
toJson() => {'someValue': this.someValue}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toJson() => {'someValue': this.someValue}; | |
toJson() => {'someValue': someValue}; |
#### TL;DR | ||
|
||
Ensure that your `Action` and `State` implement a `toJson` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that your `Action` and `State` implement a `toJson` method. | |
Ensure that your `Action`s and `State` implement a `toJson` method. |
|
||
[//]: # () | ||
[//]: # (The strategy described above should work for most cases. However, if you want to do something different, you can replace the ActionEncoder and StateEncoder with your own implementations:) | ||
|
||
[//]: # () | ||
[//]: # (var remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000', actionEncoder: MyCoolActionEncoder);) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[//]: # (___Overriding these strategies___) | |
[//]: # () | |
[//]: # (The strategy described above should work for most cases. However, if you want to do something different, you can replace the ActionEncoder and StateEncoder with your own implementations:) | |
[//]: # () | |
[//]: # (var remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000', actionEncoder: MyCoolActionEncoder);) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greglittlefield-wf could you also take a look at this and see if you have any feedback?
bool foo = false; | ||
|
||
Map<String,dynamic> toJson() => {'foo':foo}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map<String,dynamic> toJson() => {'foo':foo}; | |
Map<String, dynamic> toJson() => {'foo':foo}; |
In order to display the properties of Dart based `Action`s and `State` in the DevTools they must implement a `toJson` method. | ||
|
||
`toJson` can be manually added to the classes, or added with the help of something like the the [json_serializable](https://pub.dev/packages/json_serializable) library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should mention that all values need to be json encodable if a value contains objects that are not directly encodable to JSON (a value that is not a number, boolean, string, null, list or a map with string keys) we will attempt to call toJson
on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment and some nits, otherwise LGTM!
enum FooAction { | ||
ACTION_1, | ||
ACTION_2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#nit semicolons aren't valid here
ACTION_2; | |
ACTION_2, |
Skynet test results failed initially for this build but were approved by greg.littlefield |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+10
@Workiva/release-management-p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 from RM
Motivation
There was a support question on how to properly integrate with the devtools for a module. It appears that these steps don't exist here yet.
Changes
Release Notes
Review
See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.
Please review:
QA Checklist
Merge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: