1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-19 23:06:42 +02:00
TableFilter/src/feature.js

98 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-11-14 16:14:13 +01:00
const NOTIMPLEMENTED = 'Not implemented.';
2016-06-19 07:07:49 +02:00
/**
* Base class defining the interface of a TableFilter feature
*/
2015-11-14 16:14:13 +01:00
export class Feature {
2016-06-19 07:07:49 +02:00
/**
* Creates an instance of Feature
* @param {Object} tf TableFilter instance
* @param {String} feature Feature name known by TableFilter
*/
2015-11-14 16:14:13 +01:00
constructor(tf, feature) {
2016-06-19 07:07:49 +02:00
/**
* TableFilter instance
* @type {TableFilter}
*/
2015-11-14 16:14:13 +01:00
this.tf = tf;
2016-06-19 07:07:49 +02:00
/**
* Feature name
* @type {String}
*/
2015-11-14 16:14:13 +01:00
this.feature = feature;
2016-06-19 07:07:49 +02:00
/**
* TableFilter feature setting
* @type {Boolean}
*/
this.enabled = tf[feature];
2016-06-19 07:07:49 +02:00
/**
* TableFilter configuration
* @type {Object}
*/
2015-11-14 16:14:13 +01:00
this.config = tf.config();
2016-06-19 07:07:49 +02:00
/**
* TableFilter emitter instance
* @type {Emitter}
*/
this.emitter = tf.emitter;
2016-06-19 07:07:49 +02:00
/**
* Field indicating whether Feature is initialized
* @type {Boolean}
*/
2015-11-14 16:14:13 +01:00
this.initialized = false;
2016-12-24 13:35:26 +01:00
/** Subscribe to destroy event */
this.emitter.on(['destroy'], () => this.destroy());
2015-11-14 16:14:13 +01:00
}
2016-06-19 07:07:49 +02:00
/**
* Initialize the feature
*/
2015-11-14 16:14:13 +01:00
init() {
throw new Error(NOTIMPLEMENTED);
}
2016-06-19 07:07:49 +02:00
/**
* Reset the feature after being disabled
*/
2015-11-14 16:14:13 +01:00
reset() {
this.enable();
this.init();
}
2016-06-19 07:07:49 +02:00
/**
* Destroy the feature
*/
2015-11-14 16:14:13 +01:00
destroy() {
throw new Error(NOTIMPLEMENTED);
}
2016-06-19 07:07:49 +02:00
/**
* Enable the feature
*/
2015-11-14 16:14:13 +01:00
enable() {
this.enabled = true;
}
2016-06-19 07:07:49 +02:00
/**
* Disable the feature
*/
2015-11-14 16:14:13 +01:00
disable() {
this.enabled = false;
}
2016-06-19 07:07:49 +02:00
/**
* Indicate whether the feature is enabled or not
* @returns {Boolean}
*/
2015-11-14 16:14:13 +01:00
isEnabled() {
return this.enabled;
}
}