Skip to content

Commit

Permalink
Added code snippet for react-redux connected components (#501)
Browse files Browse the repository at this point in the history
* added vscode snippets for connected components

* added intelij snippet

* removed extra ignore comment

* formatted json file

* address pr comments
  • Loading branch information
matthewnitschke-wk authored Jul 2, 2020
1 parent 0f6d8dd commit 8b01ee5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions snippets/snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,30 @@
"}"
],
"description": "Creates a stateful OverReact component with abbreviated props and state declarations"
},
"connectedStatelessComponent": {
"prefix": "orStlessConnect",
"body": [
"import 'package:over_react/over_react.dart';",
"import 'package:over_react/over_react_redux.dart';",
"",
"part '${1:FileName}.over_react.g.dart';",
"",
"UiFactory<${2:MyComponent}Props> ${2:MyComponent} = connect<${3:SomeReduxStoreState}, ${2:MyComponent}Props>(",
"\tmapStateToProps: (state) => (${2:MyComponent}()),",
"\tmapDispatchToProps: (dispatch) => (${2:MyComponent}()),",
")(_$${2:MyComponent}); // ignore: undefined_identifier",
"",
"mixin ${2:MyComponent}Props on UiProps {}",
"",
"class ${2:MyComponent}Component extends UiComponent2<${2:MyComponent}Props> {",
"\t@override",
"\tget defaultProps => (newProps());",
"",
"\t@override",
"\trender() { }",
"}"
],
"description": "Creates a stateless and connected OverReact component"
}
}
8 changes: 8 additions & 0 deletions snippets/snippets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@
<option name="DART" value="true" />
</context>
</template>
<template name="orStlessConnect" value="import 'package:over_react/over_react.dart';&#10;import 'package:over_react/over_react_redux.dart';&#10;&#10;part '$FileName$.over_react.g.dart';&#10;&#10;UiFactory&lt;$MyComponent$Props&gt; $MyComponent$ = connect&lt;$SomeReduxStoreState$, $MyComponent$Props&gt;(&#10; mapStateToProps: (state) =&gt; ($MyComponent$()),&#10; mapDispatchToProps: (dispatch) =&gt; ($MyComponent$()),&#10;)(_$$$MyComponent$); // ignore: undefined_identifier&#10;&#10;mixin $MyComponent$Props on UiProps {}&#10;&#10;class $MyComponent$Component extends UiComponent2&lt;$MyComponent$Props&gt; {&#10; @override&#10; get defaultProps =&gt; (newProps());&#10;&#10; @override&#10; render() { }&#10;}" description="Creates a stateless and connected over_react component" toReformat="false" toShortenFQNames="true">
<variable name="FileName" expression="" defaultValue="&quot;foo&quot;" alwaysStopAt="true" />
<variable name="MyComponent" expression="" defaultValue="&quot;Foo&quot;" alwaysStopAt="true" />
<variable name="SomeReduxStoreState" expression="" defaultValue="&quot;Foo&quot;" alwaysStopAt="true" />
<context>
<option name="DART" value="true" />
</context>
</template>

0 comments on commit 8b01ee5

Please sign in to comment.