weekend-spa v0.0.3
Weekend-SPA
Wrapper for making single page applications with JsRender. See JsRender API for how to make html templates.
API
Renderer
Class for binding and rendering views. Create an instance of Renderer to persist the bindings, which causes any link with the class "pop" to trigger the rendering without reloading the page.
Kind: global class
- Renderer
- instance
- static
- .bindView([view], [url], [contextData], [callbackFn], [selector])
- .bindViewToSelector(selector, [view], [url], [contextData], [callbackFn])
- .bindViewWithJSON(view, [url], jsonUrl, dataName, [callbackFn], [additionalData], [selector])
- .renderView(viewFile, [contextData], [callbackFn], [selector], [viewsFolder]) ⇒ Promise
renderer.bindView(view, url, contextData, callbackFn, selector)
Binds a view to a URL
Kind: instance method of Renderer
Param | Type | Description |
---|---|---|
view | string | The HTML file to render |
url | string | The path of the view |
contextData | Object | function | Object containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. A provided function can execute any code and has access to the parameters Renderer and pathParams. |
callbackFn | function | string | a function with parameter (contextData) to run after the view is rendered. |
selector | string | Supply a selector to bind with selector instead of only url |
renderer.bindViewWithJSON(view, url, jsonUrl, dataName, callbackFn, additionalData, selector)
Binds a view to a URL (and optionally a selector), and fetches JSON data to use as tag arguments. For more complex operations than basic JSON fetching, please use the normal bindView with contextData supplied as a function.
Kind: instance method of Renderer
Param | Type | Default | Description |
---|---|---|---|
view | string | name of the html file with the template to render | |
url | string | URL to bind to | |
jsonUrl | string | Array.<string> | URL(s) for JSON to fetch | |
dataName | string | Array.<string> | "data" | name of the data as it is written in the html template file, for example: 'movie' results in the data being accessible with {{:movie}}. Pass one string for each JSON. |
callbackFn | function | a function to run each time the view is rendered. | |
additionalData | Object | string | Additional data to be available in the template and callback. Must be a "true" object that can be Object.assign()ed onto the fetched data. | |
selector | string | Only necessary if the selector does not have the class 'pop' |
renderer.renderView(viewFile, contextData, callbackFn, selector, viewsFolder) ⇒ Promise
Renders a view
Kind: instance method of Renderer
Param | Type | Default | Description |
---|---|---|---|
viewFile | string | function | Pass empty string to only call the callback function. | |
contextData | Object | Object containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. | |
callbackFn | function | a function with parameter (contextData) to run after the view is rendered. | |
selector | string | "'#root'" | Target selector to insert html in, default #root |
viewsFolder | string | "'/views/'" | default /views/ |
Renderer.bindView(view, url, contextData, callbackFn, selector)
Binds a view to a URL
Kind: static method of Renderer
Param | Type | Description |
---|---|---|
view | string | The HTML file to render |
url | string | The path of the view |
contextData | Object | function | Object containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. A provided function can execute any code and has access to the parameters Renderer and pathParams. |
callbackFn | function | string | a function with parameter (contextData) to run after the view is rendered. |
selector | string | Supply a selector to bind with selector instead of only url |
Renderer.bindViewToSelector(selector, view, url, contextData, callbackFn)
Binds a view to a selector and a URL
Kind: static method of Renderer
Param | Type | Default | Description |
---|---|---|---|
selector | string | Selector to bind to | |
view | string | The HTML file to render | |
url | string | The path of the view | |
contextData | Object | function | Object containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. A provided function can execute any code and has access to the parameters Renderer and pathParams. | |
callbackFn | function | a function with parameter (contextData) to run each time the view is rendered. |
Renderer.bindViewWithJSON(view, url, jsonUrl, dataName, callbackFn, additionalData, selector)
Binds a view to a URL (and optionally a selector), and fetches JSON data to use as tag arguments. For more complex operations than basic JSON fetching, please use the normal bindView with contextData supplied as a function.
Kind: static method of Renderer
Param | Type | Default | Description |
---|---|---|---|
view | string | name of the html file with the template to render | |
url | string | URL to bind to | |
jsonUrl | string | Array.<string> | URL(s) for JSON to fetch | |
dataName | string | Array.<string> | "data" | name of the data as it is written in the html template file, for example: 'movie' results in the data being accessible with {{:movie}}. Pass one string for each JSON. |
callbackFn | function | a function to run each time the view is rendered. | |
additionalData | Object | string | Additional data to be available in the template and callback. Must be a "true" object that can be Object.assign()ed onto the fetched data. | |
selector | string | Only necessary if the selector does not have the class 'pop' |
Renderer.renderView(viewFile, contextData, callbackFn, selector, viewsFolder) ⇒ Promise
Renders a view
Kind: static method of Renderer
Param | Type | Default | Description |
---|---|---|---|
viewFile | string | function | Pass empty string to only call the callback function. | |
contextData | Object | Object containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. | |
callbackFn | function | a function with parameter (contextData) to run after the view is rendered. | |
selector | string | "'#root'" | Target selector to insert html in, default #root |
viewsFolder | string | "'/views/'" | default /views/ |
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago