-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
12 changed files
with
993 additions
and
116 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
const PKG_NAME = 'oxium'; | ||
export const PKG_NAME = 'oxium'; | ||
|
||
const ID = 'id'; | ||
const HANDLER = 'handler'; | ||
const IS_LOADED = 'isLoaded'; | ||
const FEATURES = 'features'; | ||
const META = '_'; | ||
export const ID = 'id'; | ||
export const HANDLER = 'handler'; | ||
export const IS_LOADED = 'isLoaded'; | ||
export const FEATURES = 'features'; | ||
export const META = '_'; | ||
|
||
export { PKG_NAME }; | ||
|
||
export { ID, FEATURES, META, HANDLER, IS_LOADED }; | ||
export const HANDLER_NOT_READY_RESULT = false; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import { compose, curry, map, not, then, when } from 'ramda'; | ||
import { compose, converge, map, not, o, pipe, when } from 'ramda'; | ||
import { getFeatures } from './lens/app'; | ||
import { promiseAll } from './util/async'; | ||
import { promiseAllAndThen } from './util/promise'; | ||
import applyFeatureTo from './util/applyFeatureTo'; | ||
import replaceFeaturesIn from './util/replaceFeaturesIn'; | ||
import pipeAsync from './util/pipeAsync'; | ||
|
||
const createAppRunner = curry((filterFn, isDoneFn, app) => { | ||
const runAgainOrReturn = when( | ||
compose(not, isDoneFn), | ||
createAppRunner(filterFn, isDoneFn), | ||
); | ||
const resolveFeaturesWith = converge(pipeAsync, [ | ||
o(map, applyFeatureTo), | ||
o(promiseAllAndThen, replaceFeaturesIn), | ||
]); | ||
|
||
return compose( | ||
then(compose(runAgainOrReturn, replaceFeaturesIn(app))), | ||
promiseAll, | ||
map(applyFeatureTo(app)), | ||
filterFn, | ||
getFeatures, | ||
)(app); | ||
}); | ||
const takeFeatures = fn => pipe(getFeatures, fn); | ||
|
||
const createAppRunner = (filterFn, isDoneFn) => { | ||
const runAgain = app => createAppRunner(filterFn, isDoneFn)(app); | ||
const shouldRunAgain = compose(not, isDoneFn); | ||
|
||
return app => | ||
pipeAsync( | ||
takeFeatures(filterFn), | ||
resolveFeaturesWith(app), | ||
when(shouldRunAgain, runAgain), | ||
)(app); | ||
}; | ||
|
||
export default createAppRunner; |
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 |
---|---|---|
@@ -1,39 +1,25 @@ | ||
import { | ||
always, | ||
applyTo, | ||
compose, | ||
converge, | ||
curry, | ||
identity, | ||
ifElse, | ||
then, | ||
} from 'ramda'; | ||
import { cata, isFunction } from 'ramda-adjunct'; | ||
import { curry } from 'ramda'; | ||
import { isFunction } from 'ramda-adjunct'; | ||
import { getHandler, setFeatureIsLoaded } from '../lens/feature'; | ||
import { ensureEitherOrRight } from './either'; | ||
import { ensurePromise } from './async'; | ||
import { ensurePromise } from './promise'; | ||
import pipeAsync from './pipeAsync'; | ||
import { HANDLER_NOT_READY_RESULT } from '../constants'; | ||
|
||
const mapRightResult = converge(compose, [ | ||
always(setFeatureIsLoaded(true)), | ||
ifElse(isFunction, identity, always(identity)), | ||
]); | ||
const transformRightResult = setFeatureIsLoaded(true); | ||
|
||
const mapLeftResult = always(identity); | ||
const applyFeatureTo = curry(async (app, feature) => { | ||
const handler = getHandler(feature); | ||
const result = await ensurePromise(handler(app)); | ||
|
||
const resolveHandler = curry((app, handler) => | ||
compose(then(ensureEitherOrRight), ensurePromise, handler)(app), | ||
); | ||
if (result === HANDLER_NOT_READY_RESULT) { | ||
return feature; | ||
} | ||
|
||
const callFeatureWith = curry((app, feature) => | ||
compose(resolveHandler(app), getHandler)(feature), | ||
); | ||
if (isFunction(result)) { | ||
return pipeAsync(transformRightResult, result)(feature); | ||
} | ||
|
||
const applyFeatureTo = curry((app, feature) => | ||
compose( | ||
then(applyTo(feature)), | ||
then(cata(mapLeftResult, mapRightResult)), | ||
callFeatureWith, | ||
)(app, feature), | ||
); | ||
return transformRightResult(feature); | ||
}); | ||
|
||
export default applyFeatureTo; |
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
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
import { andThen, call, pipeWith, unapply, useWith } from 'ramda'; | ||
import { ensurePromise } from './promise'; | ||
|
||
const pipeAsync = unapply(pipeWith(useWith(call, [andThen, ensurePromise]))); | ||
|
||
export default pipeAsync; |
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,8 @@ | ||
import { andThen, pipe, unless } from 'ramda'; | ||
import { allP, isPromise } from 'ramda-adjunct'; | ||
|
||
export const toPromise = value => Promise.resolve(value); | ||
|
||
export const ensurePromise = unless(isPromise, toPromise); | ||
|
||
export const promiseAllAndThen = fn => pipe(allP, andThen(fn)); |