@/store#DripTableGeneratorState TypeScript Examples

The following examples show how to use @/store#DripTableGeneratorState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: drip-table-generator.tsx    From drip-table with MIT License 5 votes vote down vote up
useTableRoot = <
RecordType extends DripTableRecordTypeBase = DripTableRecordTypeBase,
ExtraOptions extends DripTableExtraOptions = DripTableExtraOptions>(
    props: DripTableGeneratorProps<RecordType, ExtraOptions>,
    store: [DripTableGeneratorState, React.Dispatch<React.SetStateAction<DripTableGeneratorState>>],
    wrapper: React.MutableRefObject<GeneratorWrapperHandler | null>,
  ) => {
  const [state, setState] = store;

  const getSchemaValue = (): DripTableSchema<DripTableColumnSchema> => {
    if (wrapper.current) {
      const currentState = wrapper.current.getState();
      return {
        ...filterAttributes(currentState.globalConfigs, '$version'),
        columns: currentState.columns.map(item => generateColumn(item)),
      };
    }

    return {
      ...filterAttributes(state.globalConfigs, '$version'),
      columns: state.columns.map(item => generateColumn(item)),
    };
  };

  const getDataSource = () => {
    if (wrapper.current) {
      const currentState = wrapper.current.getState();
      return currentState.previewDataSource;
    }
    return state.previewDataSource;
  };

  const context = {
    ...props,
    ...state,
    getSchemaValue,
    getDataSource,
    setGlobalData: setState,
  };

  return context;
}