page

A minimalistic page creation library for Apple TV applications
Author:
Source:

Methods

(static) create(name, cfg) → {function}

Create a page that can be later used for navigation.
Source:
Parameters:
Name Type Description
name String | Object Name of the page or the configuration options
cfg Object Page configuration options
Returns:
Type:
function
A function that returns promise upon execution
Example
const homepage = create({
    name: 'homepage',
    url: 'path/to/server/api/',
    template(data) {
        // return a string here (preferably TVML)
    },
    data(d) {
        // do your data transformations here and return the final data
        // the transformed data will be passed on to your template function
    },
    options: {
        // ajax options
    },
    events: {
        // event maps and handlers on the configuration object
        'scroll': function(e) { // do the magic here },
        'select': 'onTitleSelect'
    },
    onError(response, xhr) {
        // perform the error handing
    },
    ready(options, resolve, reject) {
        // call resolve with the data to render the provided template

        // you may also call resolve with null/falsy value to suppress rendering,
        // this is useful when you want full control of the page rendering

        // reject is not preferred, but you may still call it

        // any configuration options passed while calling the page method,
        // will be carried over to ready method at runtime
    },
    afterReady(doc) {
        // all your code that relies on a document object should go here
    },
    onTitleSelect(e) {
        // do the magic here
    }
});
homepage(options) -> promise that resolves to a document

//(or if using the navigation class)

Navigation.navigate('homepage') -> promise that resolves on navigation

(static) get(name) → {Page}

Returns the previously created page from the cache.
Source:
Parameters:
Name Type Description
name string Name of the previously created page
Returns:
Type:
Page
Page function
Example
// create page
ATV.Page.create('homepage', { page configurations });
// later in the app
const homepage = ATV.Page.get('homepage');

(static) makeDom(cfg, response) → {Document}

A helper method that calls the data method to transform the data. It then creates a dom from the provided template and the final data.
Source:
Parameters:
Name Type Description
cfg Object Page configuration options
response Object The data object
Returns:
Type:
Document
The newly created document

(static) prepareDom(doc) → {Document}

Prepares a document by adding styles and event handlers.
Source:
Parameters:
Name Type Description
doc Document The document to prepare
Returns:
Type:
Document
The document passed

(static) setOptions(cfg)

Sets the default options for the page.
Source:
Parameters:
Name Type Description
cfg Object The configuration object {defaults}