r3-v2/dist/r3-node/r3-component.js

172 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-06-20 20:46:13 +02:00
const Event = require('r3-event');
2021-06-18 13:54:08 +02:00
const Utils = require('r3-utils');
2021-06-20 20:46:13 +02:00
const R3Object = require('r3-r3-object.js');
2021-06-18 13:54:08 +02:00
/**
OPTIONS_START
2021-06-20 20:46:13 +02:00
runtime='default'
2021-06-18 13:54:08 +02:00
OPTIONS_END
2021-06-19 16:41:42 +02:00
INSTANCE_OPTIONS_MAPPING_START
INSTANCE_OPTIONS_MAPPING_END
2021-06-18 13:54:08 +02:00
LINKED_OBJECTS_START
LINKED_OBJECTS_END
2021-06-19 16:41:42 +02:00
EXCLUDED_FROM_INSTANCE_OPTIONS_START
2021-06-20 20:46:13 +02:00
runtime
2021-06-19 16:41:42 +02:00
EXCLUDED_FROM_INSTANCE_OPTIONS_END
2021-06-18 13:54:08 +02:00
**/
2021-06-20 20:46:13 +02:00
class Component extends R3Object {
2021-06-18 13:54:08 +02:00
2021-06-19 16:41:42 +02:00
//CONSTRUCTOR_EXTENDS_TEMPLATE_START
2021-06-18 13:54:08 +02:00
constructor(options) {
2021-06-19 16:41:42 +02:00
if (Utils.UndefinedOrNull(options)) {
options = {};
}
2021-06-18 13:54:08 +02:00
super(options);
2021-06-19 16:41:42 +02:00
this.emit(Event.OBJECT_CREATED, this);
2021-06-18 13:54:08 +02:00
//OPTIONS_INIT_START
2021-06-20 20:46:13 +02:00
if (typeof options === 'undefined') {
options = {};
2021-06-20 08:13:06 +02:00
}
2021-06-20 20:46:13 +02:00
if (Utils.UndefinedOrNull(options.runtime)) {
options.runtime = 'default';
2021-06-20 08:13:06 +02:00
}
2021-06-19 11:27:32 +02:00
//OPTIONS_INIT_END
2021-06-18 13:54:08 +02:00
2021-06-19 16:41:42 +02:00
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
2021-06-20 20:46:13 +02:00
this.emit(Event.COMPONENT_INITIALIZED, this);
2021-06-19 16:41:42 +02:00
//CUSTOM_BEFORE_INIT_END
this.emit(Event.OBJECT_INITIALIZED, this);
2021-06-18 13:54:08 +02:00
}
2021-06-19 16:41:42 +02:00
//CONSTRUCTOR_EXTENDS_TEMPLATE_END
2021-06-18 13:54:08 +02:00
2021-06-19 16:41:42 +02:00
//CREATE_INSTANCE_TEMPLATE_START
2021-06-18 13:54:08 +02:00
createInstance() {
//CREATE_INSTANCE_BEFORE_START
2021-06-20 20:46:13 +02:00
this.emit(Event.CREATE_INSTANCE_BEFORE, this);
2021-06-18 13:54:08 +02:00
//CREATE_INSTANCE_BEFORE_END
2021-06-19 16:41:42 +02:00
//CUSTOM_CREATE_INSTANCE_START
//CUSTOM_CREATE_INSTANCE_END
2021-06-18 13:54:08 +02:00
//CREATE_INSTANCE_AFTER_START
2021-06-20 20:46:13 +02:00
this[this.runtime].createInstance(
this,
{
//CREATE_INSTANCE_OPTIONS_START
//CREATE_INSTANCE_OPTIONS_END
}
)
2021-06-19 16:41:42 +02:00
this.emit(Event.INSTANCE_CREATED, this);
2021-06-18 13:54:08 +02:00
//CREATE_INSTANCE_AFTER_END
}
2021-06-19 16:41:42 +02:00
//CREATE_INSTANCE_TEMPLATE_END
2021-06-18 13:54:08 +02:00
2021-06-19 16:41:42 +02:00
//UPDATE_INSTANCE_TEMPLATE_START
updateInstance(property) {
2021-06-18 13:54:08 +02:00
//UPDATE_INSTANCE_BEFORE_START
2021-06-19 16:41:42 +02:00
this.emit(Event.UPDATE_INSTANCE_BEFORE, this);
//UPDATE_INSTANCE_BEFORE_END
//UPDATE_INSTANCE_OPTIONS_START
//UPDATE_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_INSTANCE_START
//CUSTOM_UPDATE_INSTANCE_END
2021-06-18 13:54:08 +02:00
//UPDATE_INSTANCE_AFTER_START
2021-06-19 16:41:42 +02:00
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
//UPDATE_INSTANCE_AFTER_END
2021-06-18 13:54:08 +02:00
}
2021-06-19 16:41:42 +02:00
//UPDATE_INSTANCE_TEMPLATE_END
2021-06-18 13:54:08 +02:00
2021-06-19 16:41:42 +02:00
//UPDATE_FROM_INSTANCE_TEMPLATE_START
updateFromInstance(property) {
2021-06-18 13:54:08 +02:00
//UPDATE_FROM_INSTANCE_BEFORE_START
2021-06-19 16:41:42 +02:00
this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this);
//UPDATE_FROM_INSTANCE_BEFORE_END
//UPDATE_FROM_INSTANCE_OPTIONS_START
//UPDATE_FROM_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_FROM_INSTANCE_START
//CUSTOM_UPDATE_FROM_INSTANCE_END
2021-06-18 13:54:08 +02:00
//UPDATE_FROM_INSTANCE_AFTER_START
2021-06-19 16:41:42 +02:00
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
//UPDATE_FROM_INSTANCE_AFTER_END
}
//UPDATE_FROM_INSTANCE_TEMPLATE_END
//DISPOSE_TEMPLATE_START
dispose() {
//DISPOSE_BEFORE_START
2021-06-20 20:46:13 +02:00
this.subscribe(
Event.INSTANCE_DISPOSED,
function(object) {
if (object === this) {
this.emit(Event.DISPOSE_OBJECT, this);
}
}
);
2021-06-19 16:41:42 +02:00
//DISPOSE_BEFORE_END
//CUSTOM_DISPOSE_START
//CUSTOM_DISPOSE_END
//DISPOSE_AFTER_START
2021-06-20 20:46:13 +02:00
this.disposeInstance();
2021-06-19 16:41:42 +02:00
//DISPOSE_AFTER_END
2021-06-18 13:54:08 +02:00
}
2021-06-19 16:41:42 +02:00
//DISPOSE_TEMPLATE_END
//DISPOSE_INSTANCE_TEMPLATE_START
disposeInstance() {
//DISPOSE_INSTANCE_BEFORE_START
2021-06-20 20:46:13 +02:00
console.log('Disposing instance of ' + this.name);
2021-06-19 16:41:42 +02:00
//DISPOSE_INSTANCE_BEFORE_END
//CUSTOM_DISPOSE_INSTANCE_START
//CUSTOM_DISPOSE_INSTANCE_END
//DISPOSE_INSTANCE_AFTER_START
2021-06-20 20:46:13 +02:00
this.emit(Event.DISPOSE_INSTANCE, this);
2021-06-19 16:41:42 +02:00
//DISPOSE_INSTANCE_AFTER_END
}
//DISPOSE_INSTANCE_TEMPLATE_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END
2021-06-20 20:46:13 +02:00
module.exports = Component;