Skip to content

Instantly share code, notes, and snippets.

@michaelsbradleyjr
Last active September 2, 2019 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelsbradleyjr/271c3dabdabf68412e254d52b3934e62 to your computer and use it in GitHub Desktop.
Save michaelsbradleyjr/271c3dabdabf68412e254d52b3934e62 to your computer and use it in GitHub Desktop.
// in the top parts of the module with other imports/requires
const {fromEvent: rxFromEvent, interval: rxInterval, partition: rxPartition} = require('rxjs');
const {debounce: rxDebounce} = require('rxjs/operators');
const {AsyncIterableX: {from: ixFrom}, batch: ixBatch} = require('ix/asynciterable');
// -----------------------------------------------------------------------------
const fileChanges$ = rxFromEvent(engine.events, 'file-event');
const [assets$, others$] = rxPartition(
fileChanges$,
({fileType}) => fileType === 'asset'
);
const [contractsAndConfigs$] = rxPartition(
others$,
({fileType}) => ['config', 'contract'].includes(fileType)
);
ixBatch(ixFrom(assets$.pipe(rxDebounce(() => rxInterval(50))))).forEach(async () => {
await engine.events.request2('pipeline:generateAll');
engine.events.emit('outputDone');
});
ixBatch(ixFrom(contractsAndConfigs$.pipe(rxDebounce(() => rxInterval(50))))).forEach(async () => {
const contractsFiles = await engine.events.request2('config:contractsFiles');
const [compiledContracts, contractsConfig] = await Promise.all([
engine.events.request2('compiler:contracts:compile', contractsFiles),
engine.events.request2('config:contractsConfig')
]);
const [contractsList, contractDependencies] = await engine.events.request2(
'contracts:build', contractsConfig, compiledContracts
);
await engine.events.request2(
'deployment:contracts:deploy', contractsList, contractDependencies
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment