/** * The Semi Foundation / Adapter architecture split was inspired by Material Component For Web. (https://github.com/material-components/material-components-web) * We re-implemented our own code based on the principle and added more functions we need according to actual needs. * */ import log from '../utils/log'; import { noop } from 'lodash'; export type noopFunction = (...args: any) => any; // eslint-disable-next-line export interface DefaultAdapter
, S = Record, callback?: any): void;
getCache(c: string): any;
getCaches(): any;
setCache(key: any, value: any): void;
stopPropagation(e: any): void;
persistEvent: (event: any) => void
}
class BaseFoundation, cb?: (...args: any) => void) {
return this._adapter.setState({ ...states }, cb);
}
getContext(key: string) {
return this._adapter.getContext(key);
}
/* istanbul ignore next */
getContexts() {
return this._adapter.getContexts();
}
/* istanbul ignore next */
getCaches() {
return this._adapter.getCaches();
}
getCache(key: string) {
return this._adapter.getCache(key);
}
setCache(key: string, value: any) {
return key && this._adapter.setCache(key, value);
}
stopPropagation(e: any) {
this._adapter.stopPropagation(e);
}
// Determine whether a controlled component
_isControlledComponent(key: string = 'value') { // eslint-disable-line
const props = this.getProps();
const isControlComponent = key in (props as any);
return isControlComponent;
}
// Does the user have incoming props, eg: _isInProps (value)
_isInProps(key: string) { // eslint-disable-line
const props = this.getProps();
return key in (props as any);
}
init(lifecycle?: any) {
// Subclasses should override this method to perform initialization routines (registering events, etc.)
}
destroy() {
// Subclasses should override this method to perform de-initialization routines (de-registering events, etc.)
}
/* istanbul ignore next */
log(text: string, ...rest: any) {
log(text, ...rest);
}
_persistEvent(e: any) {
// only work for react adapter for now
this._adapter.persistEvent(e);
}
}
export default BaseFoundation;