From 8309e3b459e4c840a2acba1b0a0cca25411a04b6 Mon Sep 17 00:00:00 2001 From: Joel Chen Date: Thu, 16 Jul 2020 12:49:58 -0700 Subject: [PATCH] rename LoadTokenHandler to RegisterTokenIds --- packages/subapp-server/src/index-page.jsx | 5 +++-- packages/xarc-jsx-renderer/package.json | 4 +++- packages/xarc-jsx-renderer/src/index.ts | 4 ++-- .../xarc-jsx-renderer/src/tags/IndexPage.ts | 5 +++++ .../xarc-jsx-renderer/src/tags/Literal.ts | 6 +++++ ...oadTokenHandler.ts => RegisterTokenIds.ts} | 10 ++++----- .../xarc-jsx-renderer/src/tags/Require.ts | 7 ++++++ packages/xarc-jsx-renderer/src/tags/Token.ts | 7 ++++++ ...andler.tsx => test-register-token-ids.tsx} | 10 ++++----- .../test/spec/LoadTokenHandler.spec.js | 1 - .../test/spec/jsx-renderer.spec.tsx | 22 +++++++++++++------ 11 files changed, 58 insertions(+), 23 deletions(-) rename packages/xarc-jsx-renderer/src/tags/{LoadTokenHandler.ts => RegisterTokenIds.ts} (78%) rename packages/xarc-jsx-renderer/test/jsx-templates/{test-load-token-handler.tsx => test-register-token-ids.tsx} (71%) delete mode 100644 packages/xarc-jsx-renderer/test/spec/LoadTokenHandler.spec.js diff --git a/packages/subapp-server/src/index-page.jsx b/packages/subapp-server/src/index-page.jsx index 5769e0519..1132ba39e 100644 --- a/packages/subapp-server/src/index-page.jsx +++ b/packages/subapp-server/src/index-page.jsx @@ -1,7 +1,8 @@ /* @jsx createElement */ -import { IndexPage, createElement, Token, Require, LoadTokenHandler } from "@xarc/jsx-renderer"; +import { IndexPage, createElement, Token, Require, RegisterTokenIds } from "@xarc/jsx-renderer"; import { ReserveSpot } from "subapp-web"; +import { tokenHandler } from "@xarc/index-page"; const RenderSubApps = (props, context) => { const { routeOptions } = context.user; @@ -42,7 +43,7 @@ const RenderSubApps = (props, context) => { const Template = ( - + diff --git a/packages/xarc-jsx-renderer/package.json b/packages/xarc-jsx-renderer/package.json index 925dc4510..a9a70645d 100644 --- a/packages/xarc-jsx-renderer/package.json +++ b/packages/xarc-jsx-renderer/package.json @@ -42,6 +42,7 @@ "munchy": "^1.0.7", "nyc": "^15.0.0", "prettier": "^2.0.4", + "run-verify": "^1.2.5", "sinon": "^7.2.6", "sinon-chai": "^3.3.0", "source-map-support": "^0.5.16", @@ -49,7 +50,8 @@ "ts-node": "^8.6.2", "typedoc": "^0.17.4", "typedoc-plugin-external-module-name": "^3.1.0", - "typescript": "^3.8.3" + "typescript": "^3.8.3", + "xstdout": "^0.1.1" }, "files": [ "dist", diff --git a/packages/xarc-jsx-renderer/src/index.ts b/packages/xarc-jsx-renderer/src/index.ts index 325c26b9c..4383b561a 100644 --- a/packages/xarc-jsx-renderer/src/index.ts +++ b/packages/xarc-jsx-renderer/src/index.ts @@ -10,10 +10,10 @@ import { Token } from "./tags/Token"; import { IndexPage } from "./tags/IndexPage"; import { Require } from "./tags/Require"; import { Literal } from "./tags/Literal"; -import { LoadTokenHandler } from "./tags/LoadTokenHandler"; +import { RegisterTokenIds } from "./tags/RegisterTokenIds"; /** @ignore */ -export { Component, Token, IndexPage, Require, Literal, JsxRenderer, LoadTokenHandler }; +export { Component, Token, IndexPage, Require, Literal, JsxRenderer, RegisterTokenIds }; let ELEMENT_ID = 0; diff --git a/packages/xarc-jsx-renderer/src/tags/IndexPage.ts b/packages/xarc-jsx-renderer/src/tags/IndexPage.ts index 555bc858c..e3375e459 100644 --- a/packages/xarc-jsx-renderer/src/tags/IndexPage.ts +++ b/packages/xarc-jsx-renderer/src/tags/IndexPage.ts @@ -7,6 +7,11 @@ import { Component } from "../Component"; +/** + * Start the template with DOCTYPE tag + * + * + */ export class IndexPage extends Component { static memoize(props) { return ``; diff --git a/packages/xarc-jsx-renderer/src/tags/Literal.ts b/packages/xarc-jsx-renderer/src/tags/Literal.ts index b51fb103f..0cd43604d 100644 --- a/packages/xarc-jsx-renderer/src/tags/Literal.ts +++ b/packages/xarc-jsx-renderer/src/tags/Literal.ts @@ -12,6 +12,12 @@ import * as _ from "lodash"; const MEMOIZE = {}; +/** + * Load literal data from a file and insert into the output + * + * @param props + * @param _context + */ export function Literal(props: any, _context: any) { // const renderer = context.asyncTemplate; diff --git a/packages/xarc-jsx-renderer/src/tags/LoadTokenHandler.ts b/packages/xarc-jsx-renderer/src/tags/RegisterTokenIds.ts similarity index 78% rename from packages/xarc-jsx-renderer/src/tags/LoadTokenHandler.ts rename to packages/xarc-jsx-renderer/src/tags/RegisterTokenIds.ts index a7fe22aea..ba71ab032 100644 --- a/packages/xarc-jsx-renderer/src/tags/LoadTokenHandler.ts +++ b/packages/xarc-jsx-renderer/src/tags/RegisterTokenIds.ts @@ -12,8 +12,8 @@ import { JsxRenderer } from "../JsxRenderer"; * * Usage: (*This is a JSX tag, don't call the function directly.*) * - * - With function: ` {...}}` - * - Load from source file: `` + * - With function: ` {...}}` + * - Load from source file: `` * - If the handler string starts with `"."` then it will be resolved to the full * path relative to the template's location, else it's a module for require. * - The full path of the handler will be used as `name`, but you can provide @@ -24,10 +24,10 @@ import { JsxRenderer } from "../JsxRenderer"; * Example: * * ```js - * import { IndexPage, Token, LoadTokenHandler } from "@xarc/jsx-renderer" + * import { IndexPage, Token, RegisterTokenIds } from "@xarc/jsx-renderer" * * export const Template = () => ( - * { + * { * return { * TOKEN1: context => { * return "result from TOKEN1" @@ -41,7 +41,7 @@ import { JsxRenderer } from "../JsxRenderer"; * @param props - JSX tag props * @param context - rendering context */ -export const LoadTokenHandler = (props, context) => { +export const RegisterTokenIds = (props, context) => { const renderer: JsxRenderer = context.asyncTemplate; renderer.registerTokenHandler(props.name, props.handler, props.call); }; diff --git a/packages/xarc-jsx-renderer/src/tags/Require.ts b/packages/xarc-jsx-renderer/src/tags/Require.ts index f0b5767c2..d641a33e1 100644 --- a/packages/xarc-jsx-renderer/src/tags/Require.ts +++ b/packages/xarc-jsx-renderer/src/tags/Require.ts @@ -7,6 +7,13 @@ import { processToken } from "../process-token"; +/** + * Require and invoke a token module with process handler + * + * @param props + * @param context + * @param scope + */ export function Require(props: any, context: any, scope: any) { return processToken(props, context, scope, true); } diff --git a/packages/xarc-jsx-renderer/src/tags/Token.ts b/packages/xarc-jsx-renderer/src/tags/Token.ts index e5f80a13c..932986226 100644 --- a/packages/xarc-jsx-renderer/src/tags/Token.ts +++ b/packages/xarc-jsx-renderer/src/tags/Token.ts @@ -7,6 +7,13 @@ import { processToken } from "../process-token"; +/** + * Invoke a token by its ID, which can be registered with RegisterTokenIds. + * + * @param props + * @param context + * @param scope + */ export function Token(props: any, context: any, scope: any) { return processToken(props, context, scope); } diff --git a/packages/xarc-jsx-renderer/test/jsx-templates/test-load-token-handler.tsx b/packages/xarc-jsx-renderer/test/jsx-templates/test-register-token-ids.tsx similarity index 71% rename from packages/xarc-jsx-renderer/test/jsx-templates/test-load-token-handler.tsx rename to packages/xarc-jsx-renderer/test/jsx-templates/test-register-token-ids.tsx index 2bcf8ddf3..b58311cd1 100644 --- a/packages/xarc-jsx-renderer/test/jsx-templates/test-load-token-handler.tsx +++ b/packages/xarc-jsx-renderer/test/jsx-templates/test-register-token-ids.tsx @@ -7,13 +7,13 @@ import { Require, Literal, Component, - LoadTokenHandler + RegisterTokenIds } from "../../src"; const Template = () => { return ( - { return { @@ -22,11 +22,11 @@ const Template = () => { }} /> - + - + {/* Test re-entry */} - + ); diff --git a/packages/xarc-jsx-renderer/test/spec/LoadTokenHandler.spec.js b/packages/xarc-jsx-renderer/test/spec/LoadTokenHandler.spec.js deleted file mode 100644 index 8d0ab7682..000000000 --- a/packages/xarc-jsx-renderer/test/spec/LoadTokenHandler.spec.js +++ /dev/null @@ -1 +0,0 @@ -/* eslint-disable filenames/match-regex */ diff --git a/packages/xarc-jsx-renderer/test/spec/jsx-renderer.spec.tsx b/packages/xarc-jsx-renderer/test/spec/jsx-renderer.spec.tsx index 725af4b96..251a1ee3e 100644 --- a/packages/xarc-jsx-renderer/test/spec/jsx-renderer.spec.tsx +++ b/packages/xarc-jsx-renderer/test/spec/jsx-renderer.spec.tsx @@ -16,7 +16,9 @@ import Template7 from "../jsx-templates/test7"; import Template8 from "../jsx-templates/test8"; import Template9 from "../jsx-templates/test9"; import Template91 from "../jsx-templates/test91"; -import TemplateLoadTokenHandler from "../jsx-templates/test-load-token-handler"; +import TemplateRegisterTokenIds from "../jsx-templates/test-register-token-ids"; +import * as xstdout from "xstdout"; +import { asyncVerify, runFinally } from "run-verify"; describe("IndexPage", function () { it("should have static memoize", () => { @@ -167,11 +169,17 @@ describe("Jsx Renderer", function () { renderer.initializeRenderer(); - const promise = renderer.render({}); - return promise.then(context => { - verify(context); - return renderer.render({}).then(verify); - }); + const intercept = xstdout.intercept(true); + + return asyncVerify( + () => renderer.render({}), + verify, + () => renderer.render({}), + verify, + runFinally(() => { + intercept.restore(); + }) + ); }); it("should handle failure in nesting async components", async () => { @@ -387,7 +395,7 @@ World` const renderer = new JsxRenderer({ insertTokenIds: true, templateFullPath: Path.dirname(require.resolve("../jsx-templates/test91")), - template: TemplateLoadTokenHandler + template: TemplateRegisterTokenIds }); renderer.initializeRenderer();