A data-first, event driven, parent-child structured data model for NodeJS compatible with modular-ui's data model.
Create a directory for your data model classes (e.g. controls
). The javascript file names should match the class name defined in the class javascript files.
controls/house.js
const { dm } = require('../modular-dm');
class house extends dm {
constructor() {
super();
this.streetNumber = "";
}
Init() {
// Initialization logic. This function is called after control creation.
}
}
module.exports = house;
controls/room.js
const { dm } = require('../modular-dm');
class room extends dm {
constructor() {
super();
this.doors = 1;
this.windows = 1;
}
Init() {
// Initialization logic. This function is called after control creation.
}
}
module.exports = room;
index.js
const { dmTopLevelContainer } = import('./modular-dm');
// Path to modular-dm control class files (passed to top level container) should be the absolute path to the control files directory
// or the relative path from the directory where modular-dm is installed.
var controls = dmTopLevelContainer('../controls')
// Create the data model
controls.Set({
house1: {
controlType: 'house',
room1: {
controlType: 'room',
windows: 2,
},
room2: {
controlType: 'room'
doors: 2,
}
},
house2: {
controlType: 'house',
room1: {
controlType: 'room',
windows: 3,
doors: 2
},
room2: {
controlType: 'room'
doors: 2,
}
}
});
Explain options { immeditate: true }.
use standard javascript to extend a class
const ClassB = require('./ClassB');
class ClassA extends ClassB {
...
}
modular-ui build in function to extend a javascript class with muiltiple other classes
- Importand to note that if more that one superclass contains a property/ function that has the same name, it will be overwritten by the last class containing that propery/ function
const ClassB = require('./ClassB');
const ClassC = require('./ClassC');
const ClassD = require('./ClassD');
class ClassA extends _uiClasses(ClassB, ClassC, ClassD) {
...
}
- Document SetAccess()
- Document event subscription (on & once) options
- Unsubscribe from caller 'remove' event on event unsubscription