当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript store.createStore函数代码示例

本文整理汇总了TypeScript中eez-studio-shared/store.createStore函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createStore函数的具体用法?TypeScript createStore怎么用?TypeScript createStore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createStore函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createInstrumentListStore

export function createInstrumentListStore(appStore: InstrumentAppStore | null) {
    return createStore({
        storeName: "instrument/list",
        versionTables: ["instrument/list/version"],
        versions: [
            // version 1
            `CREATE TABLE "instrument/list/version"(version INT NOT NULL);
            INSERT INTO "instrument/list/version"(version) VALUES (1);
            CREATE TABLE "instrument/list"(
                deleted INTEGER NOT NULL,
                name TEXT,
                data TEXT
            );`,

            // version 2
            `ALTER TABLE "instrument/list" ADD COLUMN type TEXT;
            UPDATE "instrument/list" SET type='table';
            UPDATE "instrument/list/version" SET version = 2;`,

            // version 3
            `ALTER TABLE "instrument/list" ADD COLUMN description TEXT;
            UPDATE "instrument/list" SET description='';
            UPDATE "instrument/list/version" SET version = 3;`,

            // version 4
            `CREATE TABLE "instrument/list-new"(
                id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
                deleted INTEGER NOT NULL,
                name TEXT,
                data TEXT,
                type TEXT,
                description TEXT);
            INSERT INTO "instrument/list-new"(id, deleted, name, data, type, description)
                SELECT ROWID, deleted, name, data, type, description FROM "instrument/list";
            DROP TABLE "instrument/list";
            ALTER TABLE "instrument/list-new" RENAME TO "instrument/list";
            UPDATE "instrument/list/version" SET version = 4;`
        ],
        properties: {
            id: types.id,
            deleted: types.boolean,
            name: types.string,
            description: types.string,
            type: types.string,
            data: types.object
        },
        create: (props: any) => {
            if (appStore) {
                const {
                    createListObject
                } = require("instrument/window/lists/factory") as typeof ListsFactoryModule;
                props = createListObject(props, appStore, appStore.instrument!);
            }
            return props;
        }
    });
}
开发者ID:eez-open,项目名称:studio,代码行数:57,代码来源:store.ts

示例2: createStore

export const activityLogStore = createStore({
    storeName: "activityLog",

    versionTables: ["activityLogVersion"],

    versions: [
        // version 1
        `CREATE TABLE activityLogVersion(version INT NOT NULL);
        INSERT INTO activityLogVersion(version) VALUES (1);
        CREATE TABLE activityLog(
            date INTEGER NOT NULL,
            oid INTEGER NOT NULL,
            type TEXT NOT NULL,
            message TEXT NOT NULL,
            data TEXT
        );
        CREATE INDEX IF NOT EXISTS activityLog_date ON activityLog(date);
        CREATE INDEX IF NOT EXISTS activityLog_oidAndDate ON activityLog(oid, date);`,

        // version 2
        `ALTER TABLE activityLog ADD COLUMN deleted BOOLEAN;
        UPDATE activityLog SET deleted=0;
        DROP INDEX activityLog_date;
        DROP INDEX activityLog_oidAndDate;
        CREATE INDEX activityLog_date ON activityLog(date, deleted);
        CREATE INDEX activityLog_oidAndDate ON activityLog(oid, date, deleted);
        UPDATE activityLogVersion SET version = 2;`,

        // version 3
        `CREATE TABLE activityLog2(
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
            date INTEGER NOT NULL,
            oid INTEGER NOT NULL,
            type TEXT NOT NULL,
            message TEXT NOT NULL,
            data TEXT,
            deleted BOOLEAN
        );
        DROP INDEX activityLog_date;
        DROP INDEX activityLog_oidAndDate;
        INSERT INTO activityLog2(id, date, oid, type, message, data, deleted)
            SELECT ROWID, date, oid, type, message, data, deleted FROM activityLog;
        DROP TABLE activityLog;
        ALTER TABLE activityLog2 RENAME TO activityLog;
        CREATE INDEX activityLog_date ON activityLog(date, deleted);
        CREATE INDEX activityLog_oidAndDate ON activityLog(oid, date, deleted);
        UPDATE activityLogVersion SET version = 3;`,

        // version 4
        `UPDATE activityLog SET type = 'instrument/file-attachment' WHERE type == "instrument/file"
            AND json_extract(message, '$.direction') = 'upload'
            AND json_extract(message, '$.sourceFilePath') IS NOT NULL;

        UPDATE activityLog SET type = 'instrument/file-download' WHERE type = 'instrument/file'
            AND json_extract(message, '$.direction') = 'upload';

        UPDATE activityLog SET type = 'instrument/file-upload' WHERE type = 'instrument/file';

        UPDATE activityLog SET message == json_replace(message, '$.state', 'upload-filesize') WHERE
            type = "instrument/file-upload" AND json_extract(message, '$.state') = 'download-filesize';

        UPDATE activityLog SET message == json_replace(message, '$.state', 'upload-start') WHERE
            type = "instrument/file-upload" AND json_extract(message, '$.state') = 'download-start';

        UPDATE activityLog SET message == json_replace(message, '$.state', 'upload-error') WHERE
            type = "instrument/file-upload" AND json_extract(message, '$.state') = 'download-error';

        UPDATE activityLog SET message == json_replace(message, '$.state', 'upload-finish') WHERE
            type = "instrument/file-upload" AND json_extract(message, '$.state') = 'download-finish';

        UPDATE activityLogVersion SET version = 4;`,

        // version 5
        // create activity-log/session's from instrument/connected with sessionName
        `INSERT INTO activityLog(date, oid, type, message, data, deleted)
            SELECT
                date-1, '0', 'activity-log/session', json_set('{}', '$.sessionName', json_extract(message, '$.sessionName')), NULL, 0
            FROM
                activityLog
            WHERE
                type="instrument/connected" AND
                json_valid(message) AND
                json_extract(message, '$.sessionName') IS NOT NULL;

        INSERT INTO activityLog(date, oid, type, message, data, deleted)
            SELECT
                date-1, '0', 'activity-log/session', json_set('{}', '$.sessionName', message), NULL, 0
            FROM
                activityLog
            WHERE
                type="instrument/connected" AND
                message IS NOT NULL AND
                message <> "" AND
                NOT json_valid(message);

        UPDATE activityLogVersion SET version = 5;`,

        // version 6
        // rename activity-log/session to activity-log/session-start
        `UPDATE activityLog SET type="activity-log/session-start" WHERE type="activity-log/session";
//.........这里部分代码省略.........
开发者ID:eez-open,项目名称:studio,代码行数:101,代码来源:activity-log.ts

示例3: createStore

export interface INotebook {
    id: string;
    name: string;
}

export const notebooksStore = createStore({
    storeName: "notebook/notebooks",
    versionTables: ["notebook/notebooks/version"],
    versions: [
        // version 1
        `CREATE TABLE "notebook/notebooks/version"(version INT NOT NULL);
        INSERT INTO "notebook/notebooks/version"(version) VALUES (1);
        CREATE TABLE "notebook/notebooks"(
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
            deleted BOOLEAN,
            name TEXT NOT NULL
        );`
    ],
    properties: {
        id: types.id,
        name: types.string,
        deleted: types.boolean
    }
});

const notebookCollection = createStoreObjectsCollection<INotebook>();

if (isRenderer()) {
    notebooksStore.watch(notebookCollection);
}
开发者ID:eez-open,项目名称:studio,代码行数:30,代码来源:store.ts

示例4: createStore

const store = createStore({
    storeName: "shortcuts/groups",
    versionTables: ["instrument/groups/version", "shortcuts/groups/version"],
    versions: [
        // version 1
        `CREATE TABLE "instrument/groups/version"(version INT NOT NULL);
        INSERT INTO "instrument/groups/version"(version) VALUES (1);
        CREATE TABLE "instrument/groups"(
            name TEXT NOT NULL
        );
        INSERT INTO "instrument/groups"(name) VALUES ('Default');`,

        // version 2
        `CREATE UNIQUE INDEX "instrument/groups/name" ON "instrument/groups"(name);
        UPDATE "instrument/groups/version" SET version = 2;`,

        // version 3
        `CREATE TABLE "shortcuts/groups-new"(name TEXT NOT NULL);
        INSERT INTO "shortcuts/groups-new"(name) SELECT name FROM "instrument/groups";
        DROP INDEX "instrument/groups/name";
        DROP TABLE "instrument/groups";
        ALTER TABLE "shortcuts/groups-new" RENAME TO "shortcuts/groups";
        CREATE UNIQUE INDEX "shortcuts/groups/name" ON "shortcuts/groups"(name);
        ALTER TABLE "instrument/groups/version" RENAME TO "shortcuts/groups/version";
        UPDATE "shortcuts/groups/version" SET version = 3;`,

        // version 4
        `ALTER TABLE "shortcuts/groups" ADD COLUMN deleted BOOLEAN;
        UPDATE "shortcuts/groups" SET deleted=0;
        UPDATE "shortcuts/groups/version" SET version = 4;`,

        // version 5
        `CREATE TABLE "shortcuts/groups-new"(
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
            deleted BOOLEAN,
            name TEXT NOT NULL);
        INSERT INTO "shortcuts/groups-new"(id, deleted, name)
            SELECT ROWID, deleted, name FROM "shortcuts/groups";
        DROP TABLE "shortcuts/groups";
        ALTER TABLE "shortcuts/groups-new" RENAME TO "shortcuts/groups";
        UPDATE "shortcuts/groups/version" SET version = 5;`
    ],
    properties: {
        id: types.id,
        name: types.string,
        deleted: types.boolean
    }
});
开发者ID:eez-open,项目名称:studio,代码行数:48,代码来源:groups-store.ts

示例5: createStore

export const store = createStore({
    storeName: "shortcuts/shortcuts",
    versionTables: [
        "instrumentShortcutsVersion",
        "instrument/shortcuts/version",
        "shortcuts/shortcuts/version"
    ],
    versions: [
        // version 1
        `CREATE TABLE instrumentShortcutsVersion(version INT NOT NULL);
        INSERT INTO instrumentShortcutsVersion(version) VALUES (1);
        CREATE TABLE instrumentShortcuts(
            name TEXT NOT NULL,
            action TEXT NOT NULL,
            keybinding TEXT
        );`,

        // version 2
        `ALTER TABLE instrumentShortcuts ADD COLUMN "group" TEXT;
        UPDATE instrumentShortcuts SET "group" = 'Default';
        ALTER TABLE instrumentShortcuts ADD COLUMN showInToolbar BOOLEAN;
        UPDATE instrumentShortcuts SET showInToolbar = 1;
        ALTER TABLE instrumentShortcuts ADD COLUMN requireConfirmation BOOLEAN;
        UPDATE instrumentShortcuts SET requireConfirmation = 0;
        UPDATE "instrumentShortcutsVersion" SET version = 2;`,

        // version 3
        `CREATE TABLE instrumentShortcutsNew(
            name TEXT NOT NULL,
            action TEXT NOT NULL,
            keybinding TEXT,
            "group" TEXT,
            showInToolbar BOOLEAN,
            requiresConfirmation BOOLEAN
        );
        INSERT INTO instrumentShortcutsNew(name, action, keybinding, "group", showInToolbar, requiresConfirmation)
            SELECT name, action, keybinding, "group", showInToolbar, requireConfirmation FROM instrumentShortcuts;
        DROP TABLE instrumentShortcuts;
        ALTER TABLE instrumentShortcutsNew RENAME TO instrumentShortcuts;
        UPDATE "instrumentShortcutsVersion" SET version = 3;`,

        // version 4
        `ALTER TABLE instrumentShortcuts ADD COLUMN toolbarButtonColor TEXT;
        UPDATE instrumentShortcuts SET toolbarButtonColor = '${DEFAULT_TOOLBAR_BUTTON_COLOR}';
        UPDATE "instrumentShortcutsVersion" SET version = 4;`,

        // version 5
        `ALTER TABLE instrumentShortcuts ADD COLUMN toolbarButtonPosition INTEGER;
        UPDATE "instrumentShortcutsVersion" SET version = 5;`,

        // version 6
        `CREATE TABLE instrumentShortcutsNew(
            name TEXT NOT NULL,
            action TEXT NOT NULL,
            keybinding TEXT,
            groupName TEXT,
            showInToolbar BOOLEAN,
            toolbarButtonColor TEXT,
            toolbarButtonPosition INTEGER,
            requiresConfirmation BOOLEAN
        );
        INSERT INTO instrumentShortcutsNew(name, action, keybinding, groupName, showInToolbar, toolbarButtonColor, toolbarButtonPosition, requiresConfirmation)
            SELECT name, action, keybinding, "group", showInToolbar, toolbarButtonColor, toolbarButtonPosition, requiresConfirmation FROM instrumentShortcuts;
        DROP TABLE instrumentShortcuts;
        ALTER TABLE instrumentShortcutsNew RENAME TO instrumentShortcuts;
        CREATE INDEX instrumentShortcuts_groupName ON instrumentShortcuts(groupName);
        UPDATE "instrumentShortcutsVersion" SET version = 6;`,

        // version 7
        `ALTER TABLE instrumentShortcutsVersion RENAME TO "instrument/shortcuts/version";
        ALTER TABLE instrumentShortcuts RENAME TO "instrument/shortcuts";
        UPDATE "instrument/shortcuts/version" SET version = 7;`,

        // version 8
        `CREATE TABLE "shortcuts/shortcuts-new"(name TEXT NOT NULL,
            action TEXT NOT NULL,
            keybinding TEXT,
            groupName TEXT,
            showInToolbar BOOLEAN,
            toolbarButtonColor TEXT,
            toolbarButtonPosition INTEGER,
            requiresConfirmation BOOLEAN);
        INSERT INTO "shortcuts/shortcuts-new"(name, action, keybinding, groupName, showInToolbar, toolbarButtonColor, toolbarButtonPosition, requiresConfirmation)
            SELECT name, action, keybinding, groupName, showInToolbar, toolbarButtonColor, toolbarButtonPosition, requiresConfirmation FROM "instrument/shortcuts";
        DROP INDEX IF EXISTS instrumentShortcuts_groupName;
        DROP TABLE "instrument/shortcuts";
        ALTER TABLE "shortcuts/shortcuts-new" RENAME TO "shortcuts/shortcuts";
        CREATE INDEX "shortcuts/shortcuts/groupName" ON "shortcuts/shortcuts"(groupName);
        ALTER TABLE "instrument/shortcuts/version" RENAME TO "shortcuts/shortcuts/version";
        UPDATE "shortcuts/shortcuts/version" SET version = 8;`,

        // version 9
        `ALTER TABLE "shortcuts/shortcuts" ADD COLUMN originalId TEXT;
        UPDATE "shortcuts/shortcuts/version" SET version = 9;`,

        // version 10
        `ALTER TABLE "shortcuts/shortcuts" ADD COLUMN deleted BOOLEAN;
        UPDATE "shortcuts/shortcuts"SET deleted=0;
        UPDATE "shortcuts/shortcuts/version" SET version = 10;`,

//.........这里部分代码省略.........
开发者ID:eez-open,项目名称:studio,代码行数:101,代码来源:shortcuts-store.ts


注:本文中的eez-studio-shared/store.createStore函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。