Created
January 19, 2019 00:39
-
-
Save mk-pmb/17f884401b562035b45084c8d0e4f6ac to your computer and use it in GitHub Desktop.
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
// -*- coding: utf-8, tab-width: 2 -*- | |
import 'p-fatal'; | |
import aux from './02_depth_aux'; | |
import pProps from './03_depth_naive'; | |
const { deepDump, identity, soon, detectState } = aux; | |
const deployment = soon({ | |
'host alice.test': { | |
'osUser ftpalice': soon({ | |
props: { home: '/var/www/alice/htdocs' }, | |
currentState: detectState(), | |
}), | |
'ftpUser alice': soon({ | |
props: { osUser: 'ftpalice' }, | |
currentState: detectState(), | |
}), | |
}, | |
'host bob.test': soon({ | |
'osUser ftpbob': { | |
props: { remove: true }, | |
currentState: detectState(), | |
}, | |
'ftpUser bob': soon({ | |
props: { remove: true }, | |
currentState: detectState(), | |
}), | |
}), | |
}); | |
const managedStuff = pProps(deployment, identity, { depth: 1 }); | |
deepDump(managedStuff); | |
const survey = pProps(deployment, identity, { depth: 2 }); | |
deepDump(survey); |
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
// -*- coding: utf-8, tab-width: 2 -*- | |
import nodeUtil from 'util'; | |
import pDelay from 'promise-delay'; | |
const aux = { | |
async deepDump(pr) { | |
const x = await pr; | |
console.log(nodeUtil.inspect(x, { depth: null })); | |
}, | |
async identity(x) { return x; }, | |
async soon(x) { | |
await pDelay(5); | |
return x; | |
}, | |
async detectState() { | |
await pDelay(3e3); | |
return 'ok'; | |
}, | |
}; | |
export default aux; |
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
// -*- coding: utf-8, tab-width: 2 -*- | |
import pPropsOrig from 'p-props'; | |
async function pProps(dictPr, refine, opts) { | |
const { depth } = opts; | |
const dict = await dictPr; | |
if (!dict) { return dict; } | |
if (!depth) { return pPropsOrig(dict, refine); } | |
const subOpt = { depth: depth - 1 }; | |
function subProps(val) { return pProps(val, refine, subOpt); } | |
return pPropsOrig(dict, subProps); | |
} | |
export default pProps; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment