private _adapter, ES6 setters and getters

This commit is contained in:
Florent Vilmart
2016-02-22 14:12:51 -05:00
parent 23e55e941e
commit 045caca946
2 changed files with 56 additions and 17 deletions

View File

@@ -8,26 +8,22 @@ based on the parameters passed
*/
// _adapter is private, use Symbol
var _adapter = Symbol();
export class AdaptableController {
/**
* Check whether the api call has master key or not.
* @param {options} the adapter options
* @param {defaultAdapter} the default adapter class or object to use
* @discussion
* Supported options types:
* - string: the options will be loaded with required, when loaded, if default
* is set on the returned object, we'll use that one to support modules
* - object: a plain javascript object (options.constructor === Object), if options.adapter is set, we'll try to load it with the same mechanics.
* - function: we'll create a new instance from that function, and pass the options object
*/
constructor(adapter, options) {
this.setAdapter(adapter, options);
constructor(adapter) {
this.adapter = adapter;
}
set adapter(adapter) {
this.validateAdapter(adapter);
this[_adapter] = adapter;
}
setAdapter(adapter, options) {
this.validateAdapter(adapter);
this.adapter = adapter;
this.options = options;
get adapter() {
return this[_adapter];
}
expectedAdapterType() {