Skip to content

Modular data model for NodeJS compatible with modular-ui

License

Notifications You must be signed in to change notification settings

bccsa/modular-dm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

modular-dm

A data-first, event driven, parent-child structured data model for NodeJS compatible with modular-ui's data model.

Installing modular-dm

Creating control classes

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;

Creating a data model

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,
        }
    }
});

Event subscription

control.on()

Explain options { immeditate: true }.


Extend Classes

Standard

use standard javascript to extend a class

const ClassB = require('./ClassB');

class ClassA extends ClassB {
    ...
}

Extend a class with multiple classes

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) {
    ...
}

To do

  • Document SetAccess()
  • Document event subscription (on & once) options
  • Unsubscribe from caller 'remove' event on event unsubscription

About

Modular data model for NodeJS compatible with modular-ui

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published