Skip to content

emit-js/controller

Repository files navigation

@emit-js/controller

emit dom controllers

controller

Install

npm install @emit-js/emit @emit-js/controller

Setup

const emit = require("@emit-js/emit")()
require("@emit-js/controller")(emit)

Usage

First create your controller composer:

module.exports = function(emit) {
  emit.controller("myController", myController)
}

async function myController() {
  // control stuff
}

Then use it:

require("./myController")(emit)
emit.myController()

Props

Commonly we append the controller name to the prop array and pass the concatenated props to sub-events.

Passing those props down produces descriptive element ids and logs that describe the call stack.

Luckily, the controller composer injects the controller name into the prop array automatically, eliminating the controller name append step.

ℹ️ Prop injection is the only thing the controller composer does at this point in time.

Related composers

Library Description URL
el DOM elements https://github.com/emit-js/el#readme
render Server side render https://github.com/emit-js/render#readme
view DOM views https://github.com/emit-js/view#readme