vscroll
Version:
Virtual scroll engine
44 lines • 2.21 kB
JavaScript
import { AdapterPropName, AdapterPropType, getDefaultAdapterProps, reactiveConfigStorage } from './props';
import core from '../../version';
import { wantedStorage, wantedUtils } from './wanted';
let instanceCount = 0;
export class AdapterContext {
constructor(config) {
const { mock, reactive } = config;
const id = ++instanceCount;
const conf = { configurable: true };
const reactivePropsStore = {};
wantedStorage.set(id, { box: {}, block: false });
// set up permanent props
Object.defineProperty(this, AdapterPropName.id, Object.assign({ get: () => id }, conf));
Object.defineProperty(this, AdapterPropName.mock, Object.assign({ get: () => mock }, conf));
Object.defineProperty(this, AdapterPropName.augmented, Object.assign({ get: () => false }, conf));
Object.defineProperty(this, AdapterPropName.version, Object.assign({ get: () => core.version }, conf));
// set up default props, they will be reassigned during the Adapter instantiation
getDefaultAdapterProps()
.filter(({ permanent }) => !permanent)
.forEach(prop => {
let { value } = prop;
// reactive props might be reconfigured by the vscroll consumer
if (reactive && prop.type === AdapterPropType.Reactive) {
const react = reactive[prop.name];
if (react) {
// here we have a configured reactive property that came from the outer config
// this prop must be exposed via Adapter, but at the same time we need to
// persist the original default value as it will be used by the Adapter internally
reactivePropsStore[prop.name] = Object.assign(Object.assign({}, react), { default: value // persisting the default native Reactive prop
});
value = react.source; // exposing the configured prop instead of the default one
}
}
Object.defineProperty(this, prop.name, Object.assign({ get: () => {
wantedUtils.setBox(prop, id);
return value;
} }, conf));
});
if (reactive) { // save both configured and default reactive props in the store
reactiveConfigStorage.set(id, reactivePropsStore);
}
}
}
//# sourceMappingURL=context.js.map