1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-17 22:06:41 +02:00
TableFilter/src/feature.js
koalyptus 37f6db7025 wip
2019-01-15 23:29:13 +11:00

101 lines
1.9 KiB
JavaScript

import {TfBase} from './tfBase';
const NOT_IMPLEMENTED = 'Not implemented.';
/**
* Base class defining the interface of a TableFilter feature
*/
export class Feature extends TfBase {
/**
* Creates an instance of Feature
* @param {Object} tf TableFilter instance
* @param {String} feature Feature name known by TableFilter
*/
constructor(tf, feature, cls) {
super(tf, cls);
/**
* TableFilter instance
* @type {TableFilter}
*/
this.tf = tf;
/**
* Feature name
* @type {String}
*/
this.feature = feature;
/**
* TableFilter feature setting
* @type {Boolean}
*/
this.enabled = tf[feature];
/**
* TableFilter configuration
* @type {Object}
*/
this.config = tf.config();
/**
* TableFilter emitter instance
* @type {Emitter}
*/
this.emitter = tf.emitter;
/**
* Field indicating whether Feature is initialized
* @type {Boolean}
*/
this.initialized = false;
/** Subscribe to destroy event */
this.emitter.on(['destroy'], () => this.destroy());
}
/**
* Initialize the feature
*/
init() {
throw new Error(NOT_IMPLEMENTED);
}
/**
* Reset the feature after being disabled
*/
reset() {
this.enable();
this.init();
}
/**
* Destroy the feature
*/
destroy() {
throw new Error(NOT_IMPLEMENTED);
}
/**
* Enable the feature
*/
enable() {
this.enabled = true;
}
/**
* Disable the feature
*/
disable() {
this.enabled = false;
}
/**
* Indicate whether the feature is enabled or not
* @returns {Boolean}
*/
isEnabled() {
return this.enabled === true;
}
}