Model

A model is an observable JavaScript object that supports the property system offered by the Dana. Here is a quick example:

import Model from "@Model";

export default Model.declare("ChannelModel", {
    properties: {
        "name" : "",
        "number": ""
    }
});

Static properties

A model can declare constants. This can be done as follows:

import ChannelModel from "@ChannelModel";

const DEFAULT_NAME = "<unknown>";

export default ChannelModel.declare("DefaultChannelModel", {
    properties: {
        "name" : DEFAULT_NAME
    }
});

External use In case the model uses constants intended to be used externally, you must declare a static class containing the constants.

import Model from "@Model";
import ProgramGenre from "@ProgramGenre";

export default Model.declare("ProgramModel", {
    properties: {
        genre : [ProgramGenre.UNDEFINED]
    }
});

Static methods

The model does not support methods nor static methods. However, you can define private static methods if you need helper functions that ease the reading of the model declaration.

import Model from "@Model";
import $Program from "@Program";
import ProgramGenre from "@ProgramGenre";

export default Model.declare("ProgramModel", {
    properties: {
        data: { class: $Program },
        genre : ({data}) => __getContentNibbles(data.contentDescription)
    }
});

/**
 * @private
 */
function __getContentNibbles(contentNibbleLevel1) {
    if (contentNibbleLevel1) {
        var programGenre = contentNibbleLevel1 * 16;
        return [programGenre];
    } else {
        return [ProgramGenre.UNDEFINED];
    }
}

Inheritance

A model can inherits from a super-model, meaning that it will merge the supermodel properties with their owns. A Model supports the ‘@abstract’ and ‘@implementation’ annotations.

import Model from "@Model";

/**
 * @abstract
 */
export default Model.declare("AbstractChannelModel", {
    properties: {
        "data": null,
        "name" : "",
        "number": ""
    }
});

import AbstractChannelModel from "@AbstractChannelModel";

/**
 * @implementation
 */
export default AbstractChannelModel.declare("ImplChannelModel", {
    properties: {
        "name" : ({data}) => data.title,
        "number": ({data}) => data.lcn
    }
});

Composition

A model can be composed of different models.

import Model from "@Model";
import Ratings from "@Ratings";
import Directors from "@Directors";
import Actors from "@Actors";
import Keywords from "@Keywords";

export default Model.declare("Media", {
     properties: {
        "title": null,
        "thumbnail": null,
        "ratings": {class: Ratings},
        "directors": {class: Directors},
        "actors": {class: Actors},
        "keywords": {class: Keywords}
    }
});