-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates for @xarc/webapp, @xarc/simple-renderer (#1685)
- Loading branch information
1 parent
c150185
commit 58f0fda
Showing
61 changed files
with
1,845 additions
and
737 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
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
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
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 |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
"dist" | ||
], | ||
"dependencies": { | ||
"munchy": "^1.0.8", | ||
"require-at": "^1.0.4", | ||
"xaa": "^1.5.0" | ||
}, | ||
|
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
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 @@ | ||
"use strict"; | ||
|
||
function tryRequire(path) { | ||
try { | ||
return require(path); | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
|
||
// Chai setup. | ||
const chai = tryRequire("chai"); | ||
if (!chai) { | ||
console.log(` | ||
mocha setup: chai is not found. Not setting it up for mocha. | ||
To setup chai for your mocha test, run 'clap mocha'.`); | ||
} else { | ||
const sinonChai = tryRequire("sinon-chai"); | ||
|
||
if (!sinonChai) { | ||
console.log(` | ||
mocha setup: sinon-chai is not found. Not setting it up for mocha. | ||
To setup sinon-chai for your mocha test, run 'clap mocha'.`); | ||
} else { | ||
chai.use(sinonChai); | ||
} | ||
|
||
// Exports | ||
global.expect = chai.expect; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SimpleRenderer } from "./simple-renderer"; |
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,68 @@ | ||
/* eslint-disable complexity */ | ||
|
||
import { TOKEN_HANDLER } from "@xarc/render-context"; | ||
|
||
const executeSteps = { | ||
STEP_HANDLER: 0, | ||
STEP_STR_TOKEN: 1, | ||
STEP_NO_HANDLER: 2, | ||
STEP_LITERAL_HANDLER: 3 | ||
}; | ||
|
||
const { STEP_HANDLER, STEP_STR_TOKEN, STEP_NO_HANDLER, STEP_LITERAL_HANDLER } = executeSteps; | ||
|
||
function renderNext(err: Error, xt) { | ||
const { renderSteps, context } = xt; | ||
if (err) { | ||
context.handleError(err); | ||
} | ||
|
||
const insertTokenId = tk => { | ||
context.output.add(`<!-- BEGIN ${tk.id} props: ${JSON.stringify(tk.props)} -->\n`); | ||
}; | ||
|
||
const insertTokenIdEnd = tk => { | ||
context.output.add(`<!-- ${tk.id} END -->\n`); | ||
}; | ||
|
||
if (context.isFullStop || context.isVoidStop || xt.stepIndex >= renderSteps.length) { | ||
const r = context.output.close(); | ||
xt.resolve(r); | ||
return null; | ||
} else { | ||
// TODO: support soft stop | ||
const step = renderSteps[xt.stepIndex++]; | ||
const tk = step.tk; | ||
const withId = step.insertTokenId; | ||
switch (step.code) { | ||
case STEP_HANDLER: | ||
if (withId) insertTokenId(tk); | ||
return context.handleTokenResult(tk.id, tk[TOKEN_HANDLER](context, tk), e => { | ||
if (withId) insertTokenIdEnd(tk); | ||
return renderNext(e, xt); | ||
}); | ||
case STEP_STR_TOKEN: | ||
context.output.add(tk.str); | ||
break; | ||
case STEP_NO_HANDLER: | ||
context.output.add(`<!-- unhandled token ${tk.id} -->`); | ||
break; | ||
case STEP_LITERAL_HANDLER: | ||
if (withId) insertTokenId(tk); | ||
context.output.add(step.data); | ||
if (withId) insertTokenIdEnd(tk); | ||
break; | ||
} | ||
return renderNext(null, xt); | ||
} | ||
} | ||
|
||
function executeRenderSteps(renderSteps, context) { | ||
return new Promise(resolve => { | ||
const xt = { stepIndex: 0, renderSteps, context, resolve }; | ||
return renderNext(null, xt); | ||
}); | ||
} | ||
|
||
const RenderExecute = { executeRenderSteps, renderNext, executeSteps }; | ||
export default RenderExecute; |
Oops, something went wrong.