import { FieldSchema } from '@ephox/boulder';
import * as Fields from '../../data/Fields';
import { dataset as datasetState } from './RepresentState';
const setValue = (component, repConfig, repState, data) => {
    const store = repConfig.store;
    repState.update([data]);
    store.setValue(component, data);
    repConfig.onSetValue(component, data);
};
const getValue = (component, repConfig, repState) => {
    const store = repConfig.store;
    const key = store.getDataKey(component);
    return repState.lookup(key).getOrThunk(() => store.getFallbackEntry(key));
};
const onLoad = (component, repConfig, repState) => {
    const store = repConfig.store;
    store.initialValue.each((data) => {
        setValue(component, repConfig, repState, data);
    });
};
const onUnload = (component, repConfig, repState) => {
    repState.clear();
};
export default [
    FieldSchema.option('initialValue'),
    FieldSchema.required('getFallbackEntry'),
    FieldSchema.required('getDataKey'),
    FieldSchema.required('setValue'),
    Fields.output('manager', {
        setValue,
        getValue,
        onLoad,
        onUnload,
        state: datasetState
    })
];
//# sourceMappingURL=DatasetStore.js.map