import { Data, replayWithLatest, tweenPipeAtom, useGeneralDriver } from './libs/mobius-utils' /** * records 和 updates 一定是成对出现的, * 在一个应用程序中,可能同时存在多个 taglet 应用,一个 taglet 应用意味着有一对 records 和 updates 的存在, * 每一个应用都对接一个 storageConnectorDriver,作为与外界进行核心数据(records 和 updates)通讯的唯一渠道 */ export const storageConnectorDriver = (options = {}) => { const storageRecordsInD = Data.empty() const storageUpdatesInD = Data.empty() const storageRecordsOutRD = replayWithLatest(1, Data.empty()) const storageUpdatesOutRD = replayWithLatest(1, Data.empty()) const runtimeRecordsInD = Data.empty() const runtimeUpdatesInD = Data.empty() const runtimeRecordsOutRD = replayWithLatest(1, Data.empty()) const runtimeUpdatesOutRD = replayWithLatest(1, Data.empty()) const recordsRD = replayWithLatest(1, Data.empty()) const updatesRD = replayWithLatest(1, Data.empty()) // runtime 接收 storage 的 records tweenPipeAtom(storageRecordsInD, runtimeRecordsOutRD) // storage 接收 runtime 的 records tweenPipeAtom(runtimeRecordsInD, storageRecordsOutRD) // runtime 接收 storage 的 updates tweenPipeAtom(storageUpdatesInD, runtimeUpdatesOutRD) // storage 接收 runtime 的 updates tweenPipeAtom(runtimeUpdatesInD, storageUpdatesOutRD) tweenPipeAtom(recordsRD, runtimeRecordsOutRD) tweenPipeAtom(recordsRD, storageRecordsOutRD) tweenPipeAtom(updatesRD, runtimeUpdatesOutRD) tweenPipeAtom(updatesRD, storageUpdatesOutRD) return { inputs: { records: recordsRD, updates: updatesRD, storageRecords: storageRecordsInD, storageUpdates: storageUpdatesInD, runtimeRecords: runtimeRecordsInD, runtimeUpdates: runtimeUpdatesInD }, outputs: { records: recordsRD, updates: updatesRD, storageRecords: storageRecordsOutRD, storageUpdates: storageUpdatesOutRD, runtimeRecords: runtimeRecordsOutRD, runtimeUpdates: runtimeUpdatesOutRD } } } export const useStorageConnectorDriver = useGeneralDriver(storageConnectorDriver)