-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(website): improve typescript docs for operators
- Loading branch information
1 parent
1f53b60
commit b4d4adb
Showing
12 changed files
with
303 additions
and
72 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
packages/overmind-website/examples/guide/goingfunctional/calloperator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const javascript = { | ||
react: [ | ||
{ | ||
fileName: 'components/MyComponent.jsx', | ||
target: 'jsx', | ||
code: ` | ||
import React from 'react' | ||
import { connect } from '../overmind' | ||
const MyComponent = ({ overmind }) => ( | ||
<button onClick={overmind.actions.functionalAction}> | ||
Test | ||
</button> | ||
) | ||
export default connect(MyComponent) | ||
`, | ||
}, | ||
], | ||
vue: [ | ||
{ | ||
fileName: 'components/MyComponent.vue (template)', | ||
target: 'markup', | ||
code: ` | ||
<button on:click="overmind.actions.functionalAction()"> | ||
Test | ||
</button> | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.vue (script)', | ||
code: ` | ||
import { connect } from '../overmind' | ||
export default connect({}) | ||
`, | ||
}, | ||
], | ||
} | ||
|
||
const typescript = { | ||
react: [ | ||
{ | ||
fileName: 'components/MyComponent.tsx', | ||
code: ` | ||
import * as React from 'react' | ||
import { connect, Connect } from '../overmind' | ||
type Props = Connect | ||
const MyComponent: React.FunctionComponent<Props> = ({ overmind }) => ( | ||
<button onClick={overmind.actions.functionalAction}> | ||
Test | ||
</button> | ||
) | ||
export default connect(MyComponent) | ||
`, | ||
}, | ||
], | ||
vue: [ | ||
{ | ||
fileName: 'components/MyComponent.vue (template)', | ||
target: 'markup', | ||
code: ` | ||
<button on:click="overmind.actions.functionalAction()"> | ||
Test | ||
</button> | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.vue (script)', | ||
code: ` | ||
import { connect } from '../overmind' | ||
export default connect({}) | ||
`, | ||
}, | ||
], | ||
angular: [ | ||
{ | ||
fileName: 'components/grabdata.component.ts', | ||
code: ` | ||
import { Component,Input } from '@angular/core'; | ||
import { connect } from '../overmind' | ||
@Component({ | ||
selector: 'grab-data', | ||
template: \` | ||
<button (click)="overmind.actions.functionalAction()"> | ||
Test | ||
</button> | ||
\` | ||
}) | ||
@connect() | ||
export class GrabData {} | ||
`, | ||
}, | ||
], | ||
} | ||
|
||
export default (ts, view) => (ts ? typescript[view] : javascript[view]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/overmind-website/examples/guide/goingfunctional/factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export default (ts) => | ||
ts | ||
? [ | ||
{ | ||
fileName: 'overmind/operators.ts', | ||
code: ` | ||
import { Operator, filter } from 'overmind' | ||
const lengthGreaterThan: (length: number) => Operator<string> = | ||
(length) => filter(({ value }) => value.length > length) | ||
`, | ||
}, | ||
] | ||
: [ | ||
{ | ||
fileName: 'overmind/operators.js', | ||
code: ` | ||
import { map, filter } from 'overmind' | ||
export const lengthGreaterThan = (length) => filter(({ value }) => value.length > length) | ||
`, | ||
}, | ||
] |
15 changes: 15 additions & 0 deletions
15
packages/overmind-website/examples/guide/typescript/action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default () => [ | ||
{ | ||
code: ` | ||
import { Action } from 'overmind' | ||
export const noArgAction: Action = ({ value }) => { | ||
value // this becomes "void" | ||
} | ||
export const argAction: Action<string> = ({ value }) => { | ||
value // this becomes "string" | ||
} | ||
`, | ||
}, | ||
] |
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
packages/overmind-website/examples/guide/typescript/operatorinfer_solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export default () => [ | ||
{ | ||
fileName: 'overmind/operators.ts', | ||
code: ` | ||
import { Operator, action } from 'overmind' | ||
export const doSomeStateChange: <T>() => Operator<T> = | ||
() => action(({ state }) => { | ||
state.foo = 'bar' | ||
}) | ||
`, | ||
}, | ||
{ | ||
fileName: 'overmind/actions.ts', | ||
code: ` | ||
import { Operator, pipe, action } from 'overmind' | ||
import { doSomeStateChange } from './operators' | ||
export const setInput: Operator<string> = pipe( | ||
doSomeStateChange<string>(), | ||
action(({ value: input, state }) => { | ||
state.input = input | ||
}) | ||
) | ||
`, | ||
}, | ||
] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/overmind-website/examples/guide/typescript/operatorpartial_solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export default () => [ | ||
{ | ||
fileName: 'overmind/operators.ts', | ||
code: ` | ||
import { Operator, filter } from 'overmind' | ||
export const filterAwesome: <T>() => Operator<{ isAwesome: boolean }, T> = | ||
() => filter(({ value: somethingAwesome }) => somethingAwesome.isAwesome) | ||
`, | ||
}, | ||
{ | ||
fileName: 'overmind/actions.ts', | ||
code: ` | ||
import { Operator, pipe, action } from 'overmind' | ||
import { filterAwesome } from './operators' | ||
import { User } from './state' | ||
export const clickedUser: Operator<User> = pipe( | ||
filterAwesome<User>(), | ||
action(({ value: user, state }) => { | ||
state.awesomeUsersClickedCount++ | ||
}) | ||
) | ||
`, | ||
}, | ||
] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.