-
-
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): improved some docs and added view helper
- Loading branch information
1 parent
75e3f2b
commit fbfa173
Showing
13 changed files
with
394 additions
and
22 deletions.
There are no files selected for viewing
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
177 changes: 177 additions & 0 deletions
177
packages/overmind-website/examples/guide/goingfunctional/callactionoperator.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,177 @@ | ||
const javascript = { | ||
react: [ | ||
{ | ||
fileName: 'overmind/actions.js', | ||
code: ` | ||
import { parallel, action } from 'overmind' | ||
export const grabData = parallel( | ||
action(async ({ state, api }) => { | ||
state.posts = await api.getPosts() | ||
}), | ||
action(async ({ state, api }) => { | ||
state.users = await api.getUsers() | ||
}) | ||
) | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.jsx', | ||
target: 'jsx', | ||
code: ` | ||
import React from 'react' | ||
import { connect } from '../overmind' | ||
const MyComponent = ({ overmind }) => ( | ||
<button onClick={overmind.actions.grabData}> | ||
Grab some data | ||
</button> | ||
) | ||
export default connect(MyComponent) | ||
`, | ||
}, | ||
], | ||
vue: [ | ||
{ | ||
fileName: 'overmind/actions.js', | ||
code: ` | ||
import { parallel, action } from 'overmind' | ||
export const grabData = parallel( | ||
action(async ({ state, api }) => { | ||
state.posts = await api.getPosts() | ||
}), | ||
action(async ({ state, api }) => { | ||
state.users = await api.getUsers() | ||
}) | ||
) | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.vue (template)', | ||
target: 'markup', | ||
code: ` | ||
<button on:click="overmind.actions.grabData()"> | ||
Grab some data | ||
</button> | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.vue (script)', | ||
code: ` | ||
import { connect } from '../overmind' | ||
export default connect({}) | ||
`, | ||
}, | ||
], | ||
} | ||
|
||
const typescript = { | ||
react: [ | ||
{ | ||
fileName: 'overmind/actions.js', | ||
code: ` | ||
import { Operator, parallel, action } from 'overmind' | ||
export const grabData: Operator = parallel( | ||
action(async ({ state, api }) => { | ||
state.posts = await api.getPosts() | ||
}), | ||
action(async ({ state, api }) => { | ||
state.users = await api.getUsers() | ||
}) | ||
) | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.tsx', | ||
code: ` | ||
import * as React from 'react' | ||
import { connect, Connect } from '../overmind' | ||
type Props = Connect | ||
const MyComponent: React.SFC<Props> = ({ overmind }) => ( | ||
<button onClick={overmind.actions.grabData}> | ||
Grab some data | ||
</button> | ||
) | ||
export default connect(MyComponent) | ||
`, | ||
}, | ||
], | ||
vue: [ | ||
{ | ||
fileName: 'overmind/actions.ts', | ||
code: ` | ||
import { Operator, parallel, action } from 'overmind' | ||
export const grabData: Operator = parallel( | ||
action(async ({ state, api }) => { | ||
state.posts = await api.getPosts() | ||
}), | ||
action(async ({ state, api }) => { | ||
state.users = await api.getUsers() | ||
}) | ||
) | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.vue (template)', | ||
target: 'markup', | ||
code: ` | ||
<button on:click="overmind.actions.grabData()"> | ||
Grab some data | ||
</button> | ||
`, | ||
}, | ||
{ | ||
fileName: 'components/MyComponent.vue (script)', | ||
code: ` | ||
import { connect } from '../overmind' | ||
export default connect({}) | ||
`, | ||
}, | ||
], | ||
angular: [ | ||
{ | ||
fileName: 'overmind/actions.js', | ||
code: ` | ||
import { Operator, parallel, action } from 'overmind' | ||
export const grabData: Operator = parallel( | ||
action(async ({ state, api }) => { | ||
state.posts = await api.getPosts() | ||
}), | ||
action(async ({ state, api }) => { | ||
state.users = await api.getUsers() | ||
}) | ||
) | ||
`, | ||
}, | ||
{ | ||
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.grabData()"> | ||
Grab some data | ||
</button> | ||
\` | ||
}) | ||
@connect() | ||
export class GrabData {} | ||
`, | ||
}, | ||
], | ||
} | ||
|
||
export default (ts, view) => (ts ? typescript[view] : javascript[view]) |
27 changes: 27 additions & 0 deletions
27
packages/overmind-website/examples/guide/goingfunctional/operatorinfer.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: Operator = | ||
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, | ||
action(({ value: input, state }) => { | ||
state.input = input | ||
}) | ||
) | ||
`, | ||
}, | ||
] |
23 changes: 23 additions & 0 deletions
23
packages/overmind-website/examples/guide/goingfunctional/operatorinputsandoutputs.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,23 @@ | ||
export default () => [ | ||
{ | ||
code: ` | ||
import { Operator, action, filter, map } from 'overmind' | ||
// You do not need to define any types, which means it defaults | ||
// its input and output to "void" | ||
export const changeSomeState: Operator = action(({ state }) => { | ||
state.foo = 'bar' | ||
}) | ||
// The second type argument is not set, but will default to "User" | ||
// The output is the same as the input | ||
export const filterAwesomeUser: Operator<User> = | ||
filter(({ value: user }) => user.isAwesome) | ||
// "map" produces a new output so we define that as the second | ||
// type argument | ||
export const getEventTargetValue: Operator<Event, string> = | ||
map(({ value: event }) => event.currentTarget.value) | ||
`, | ||
}, | ||
] |
26 changes: 26 additions & 0 deletions
26
packages/overmind-website/examples/guide/goingfunctional/operatorpartial.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 filterAwesomeUser: Operator<{ isAwesome: boolean }> = | ||
filter(({ value: somethingAwesome }) => somethingAwesome.isAwesome) | ||
`, | ||
}, | ||
{ | ||
fileName: 'overmind/actions.ts', | ||
code: ` | ||
import { Operator, pipe, action } from 'overmind' | ||
import { filterAwesomeUser } from './operators' | ||
import { User } from './state' | ||
export const clickedUser: Operator<User> = pipe( | ||
filterAwesomeUser, | ||
action(({ value: user, state }) => { | ||
state.awesomeUsersClickedCount++ | ||
}) | ||
) | ||
`, | ||
}, | ||
] |
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
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.