Skip to content

Instantly share code, notes, and snippets.

@bultas
Last active June 12, 2019 21:00
Show Gist options
  • Save bultas/f225502591c3ede59445758528d20dd3 to your computer and use it in GitHub Desktop.
Save bultas/f225502591c3ede59445758528d20dd3 to your computer and use it in GitHub Desktop.
/**
* @param {HTMLFunction} html
* @returns {(instance: Instance) => (number) => string}
*/
const template = html => instance => multiplier => html`
<h1>Hello ${instance.data.name}</h1>
<h2>count: ${2 * multiplier}</h2>
`;
/**
* @param {Instance} instance
* @returns {Promise<string>}
*/
const render = async instance => template(html)(instance)(4);
export default render;
// @ts-check
/**
* @typedef {object} BrowserHistory
* @property {(route: string) => void} push
*/
/**
* @param {BrowserHistory} history
* @returns {(route: string) => void}
*/
const push = history => route => history.push(route);
/** @type {Template} */
const template = html => instance => html`
<script type="module" src="${instance.app.static_url}/script.js"></script>
<h1>Hello World</h1>
`;
/**
* @param {Instance} instance
* @returns {Promise<string>}
*/
const render = async instance => template(html)(instance);
export default render;
{
"compilerOptions": {
"target": "es6",
"checkJs": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
],
// "include": [
// "index.js",
// "types.js"
// ]
}
/**
* @typedef {object} RequestData
* @property {Object<string, any>} query_params
* @property {array} path_info
*/
/**
* @typedef {object} AppData
* @property {string} static_url
*/
/**
* @typedef {object} ConfigData
* @property {string} api_url
*/
/**
* @typedef {object} PageData
* @property {string} name
* @property {string} id
* @property {Object<string, any>} db
*/
/**
* @typedef {object} Instance
* @property {RequestData} request
* @property {AppData} app
* @property {ConfigData} config
* @property {PageData} data
*/
/**
* @callback HTMLFunction
* @param {TemplateStringsArray} string
* @param {any} any
* @returns {string}
*/
/**
* @callback Template
* @param {HTMLFunction} html
* @returns {(instance: Instance) => string}
*/
@bultas
Copy link
Author

bultas commented Jun 8, 2019

problem with async and arrow functions

Screenshot 2019-06-08 at 02 31 53

fixed by removing arrow function

Screenshot 2019-06-08 at 02 33 20

@bultas
Copy link
Author

bultas commented Jun 8, 2019

ale pres CL ./node_modules/.bin/tsc --checkJs --target ES2016 to je jiz v poradku

@bultas
Copy link
Author

bultas commented Jun 10, 2019

@s-m-i-t-a toto funguje ...


/**
 * @callback Template
 * @param {HTMLFunction} html
 * @returns {(instance: Instance) => (something: string) => string}
 */

/**
 * @type {Template}
 */
const template = html => instance => something => html`
  <script type="module" src="${instance.app.static_url}/script.js"></script>
  <h1>Hello World</h1>
`;

@bultas
Copy link
Author

bultas commented Jun 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment