Services and Models

Services

General rules

  • Services are mostly asynchronous, if vendor API is synchronous, convert it to asynchronous with promises
  • A synchronous method must be sufixed with the keyword Sync, eg: findSync()
  • Never import the implementation directly (example below)

Examples:

Implementation import

Never import the implementation directly:

WRONG:

import $MockChannelService from "@MockChannelService"; // WRONG
import $AppScreen from @AppScreen;
export default $AppScreen.declare("HomeScreen", {
...

GOOD:

import $ChannelService from "@ChannelService"; // GOOD
import $AppScreen from @AppScreen;
export default $AppScreen.declare("HomeScreen", {
...

Models

General rules

  • Don’t access native data property (example below)
  • Don’t update one property from native data (example below)

Examples:

Native data

Don’t access native data property:

WRONG:

let movie = new $Movie();
let movieName = movie.data.title; // WRONG

GOOD:

let movie = new $Movie();
let movieName = movie.name; // GOOD

Change native data

Don’t update one property from native data:

WRONG:

let movie = new $Movie();
movie.data.title = "New Title"; // WRONG Won't change movie.name as data is a POJO not watchable

GOOD:

let movie = new $Movie();
movie.data = { title: "New Title" }; // GOOD movie.name will change as data changed