-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c786820
commit 7aae474
Showing
17 changed files
with
1,220 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import factory from '../../lib/factory'; | ||
import asyncBehavior from '../../lib/ducklings/async-behavior'; | ||
|
||
export default factory( | ||
'ducklings/app/change-secret', | ||
(service) => [asyncBehavior, ({ | ||
selector, | ||
app: {start, complete}, | ||
}) => { | ||
return { | ||
initialState: { | ||
complete: false, | ||
}, | ||
handlers: { | ||
[complete]: { | ||
next: () => ({ | ||
complete: true, | ||
}), | ||
}, | ||
}, | ||
app: { | ||
isComplete: selector((state) => state.complete), | ||
submit: (secret, settings) => (dispatch) => { | ||
dispatch(start()); | ||
return dispatch(complete(service.changeSecret(secret, settings))); | ||
}, | ||
}, | ||
}; | ||
}], | ||
); |
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,30 @@ | ||
import factory from '../../lib/factory'; | ||
import asyncBehavior from '../../lib/ducklings/async-behavior'; | ||
|
||
export default factory( | ||
'ducklings/app/clear', | ||
(service) => [asyncBehavior, ({ | ||
selector, | ||
app: {start, complete}, | ||
}) => { | ||
return { | ||
initialState: { | ||
complete: false, | ||
}, | ||
handlers: { | ||
[complete]: { | ||
next: () => ({ | ||
complete: true, | ||
}), | ||
}, | ||
}, | ||
app: { | ||
isComplete: selector((state) => state.complete), | ||
submit: () => (dispatch) => { | ||
dispatch(start()); | ||
return dispatch(complete(service.clear())); | ||
}, | ||
}, | ||
}; | ||
}], | ||
); |
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,38 @@ | ||
import factory from '../../lib/factory'; | ||
import asyncBehavior from '../../lib/ducklings/async-behavior'; | ||
|
||
export default factory( | ||
'ducklings/app/create', | ||
(service) => [asyncBehavior, ({ | ||
selector, | ||
app: {start, complete}, | ||
}) => { | ||
return { | ||
initialState: { | ||
count: 0, | ||
settings: undefined, | ||
complete: false, | ||
}, | ||
handlers: { | ||
[start]: (_, {payload: settings}) => ({ | ||
settings, | ||
}), | ||
[complete]: { | ||
next: (_, {payload: count}) => ({ | ||
count, | ||
complete: true, | ||
}), | ||
}, | ||
}, | ||
app: { | ||
getCount: selector((state) => state.count), | ||
getSettings: selector((state) => state.settings), | ||
isComplete: selector((state) => state.complete), | ||
submit: (secret, settings) => (dispatch) => { | ||
dispatch(start(settings)); | ||
return dispatch(complete(service.create(secret, settings))); | ||
}, | ||
}, | ||
}; | ||
}], | ||
); |
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,33 @@ | ||
import factory from '../../lib/factory'; | ||
import asyncBehavior from '../../lib/ducklings/async-behavior'; | ||
|
||
export default factory( | ||
'ducklings/app/delete', | ||
(service) => [asyncBehavior, ({ | ||
selector, | ||
app: {start, complete}, | ||
}) => { | ||
return { | ||
initialState: { | ||
count: 0, | ||
complete: false, | ||
}, | ||
handlers: { | ||
[complete]: { | ||
next: (_, {payload: count}) => ({ | ||
count, | ||
complete: true, | ||
}), | ||
}, | ||
}, | ||
app: { | ||
getCount: selector((state) => state.count), | ||
isComplete: selector((state) => state.complete), | ||
submit: () => (dispatch) => { | ||
dispatch(start()); | ||
return dispatch(complete(service.delete())); | ||
}, | ||
}, | ||
}; | ||
}], | ||
); |
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,95 @@ | ||
import factory from '../../lib/factory'; | ||
import unlockFactory from './unlock'; | ||
import createFactory from './create'; | ||
import deleteFactory from './delete'; | ||
import clearFactory from './clear'; | ||
import changeSecretFactory from './change-secret'; | ||
import asyncBehavior from '../../lib/ducklings/async-behavior'; | ||
import { | ||
createSelector, | ||
} from 'reselect'; | ||
|
||
export default factory( | ||
'ducklings/app', | ||
(service) => [asyncBehavior, { | ||
unlock: unlockFactory(service), | ||
create: createFactory(service), | ||
delete: deleteFactory(service), | ||
clear: clearFactory(service), | ||
changeSecret: changeSecretFactory(service), | ||
}, ({ | ||
action, | ||
selector, | ||
reduce, | ||
app: {start, complete}, | ||
}) => { | ||
const count = selector((state) => state.count); | ||
const getSettings = selector((state) => state.settings); | ||
const completeUnlock = action('COMPLETE_UNLOCK'); | ||
const completeCreate = action('COMPLETE_CREATE'); | ||
const completeDelete = action('COMPLETE_DELETE'); | ||
const completeClear = action('COMPLETE_CLEAR'); | ||
return { | ||
initialState: { | ||
count: 0, | ||
settings: undefined, | ||
}, | ||
handlers: { | ||
[start]: () => ({ | ||
count: 0, | ||
}), | ||
[complete]: { | ||
next: (_, {payload: count}) => ({ | ||
count, | ||
}), | ||
}, | ||
[completeUnlock]: (state, {payload: settings}) => ({ | ||
...reduce(state, { | ||
unlock: [['reset']], | ||
}), | ||
settings, | ||
}), | ||
[completeCreate]: (state, {payload: {settings, count}}) => ({ | ||
...reduce(state, { | ||
create: [['reset']], | ||
}), | ||
settings, | ||
count, | ||
}), | ||
[completeDelete]: (state, {payload: count}) => ({ | ||
...reduce(state, { | ||
delete: [['reset']], | ||
}), | ||
settings: undefined, | ||
count, | ||
}), | ||
[completeClear]: (state) => ({ | ||
...reduce(state, { | ||
clear: [['reset']], | ||
}), | ||
settings: undefined, | ||
count: 0, | ||
}), | ||
}, | ||
app: { | ||
hasSettings: createSelector( | ||
count, | ||
(count) => count > 0, | ||
), | ||
isUnlocked: createSelector( | ||
getSettings, | ||
(settings) => typeof settings !== 'undefined', | ||
), | ||
getSettings, | ||
initialize: () => (dispatch) => { | ||
dispatch(start()); | ||
return dispatch(complete(service.initialize())); | ||
}, | ||
completeUnlock, | ||
completeCreate, | ||
completeDelete, | ||
completeClear, | ||
}, | ||
}; | ||
}], | ||
); |
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,45 @@ | ||
import factory from '../../lib/factory'; | ||
import errorBehavior from '../../lib/ducklings/error-behavior'; | ||
import { | ||
createSelector, | ||
} from 'reselect'; | ||
|
||
export default factory( | ||
'ducklings/app/unlock', | ||
(service) => [errorBehavior, ({ | ||
action, | ||
selector, | ||
}) => { | ||
const getSettings = selector((state) => state.settings); | ||
const submit = action('SUBMIT', (secret) => { | ||
try { | ||
return service.unlock(secret); | ||
} catch (error) { | ||
return error; | ||
} | ||
}); | ||
return { | ||
initialState: { | ||
settings: undefined, | ||
}, | ||
handlers: { | ||
[submit]: { | ||
next: (_, {payload: settings}) => ({ | ||
settings, | ||
}), | ||
throw: (_, {payload: error}) => ({ | ||
error, | ||
}), | ||
}, | ||
}, | ||
app: { | ||
getSettings, | ||
isComplete: createSelector( | ||
getSettings, | ||
(settings) => typeof settings !== 'undefined', | ||
), | ||
submit, | ||
}, | ||
}; | ||
}], | ||
); |
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.