當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript service.service函數代碼示例

本文整理匯總了TypeScript中eez-studio-shared/service.service函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript service函數的具體用法?TypeScript service怎麽用?TypeScript service使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了service函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

import { service } from "eez-studio-shared/service";

import { db } from "eez-studio-shared/db";

export default service<void, void>("db-services/vacuum", async () => {
    db.exec("VACUUM");
});
開發者ID:eez-open,項目名稱:studio,代碼行數:7,代碼來源:vacuum.ts

示例2: serviceImplementation

import { service } from "eez-studio-shared/service";

import { FontProperties } from "font-services/interfaces";

import * as FreeTypeModule from "font-services/freetype";

interface Params {
    font: FontProperties;
    projectFilePath: string;
}

function serviceImplementation(data: Params) {
    const { rebuildFont } = require("font-services/freetype") as typeof FreeTypeModule;
    return rebuildFont(data.font, data.projectFilePath);
}

export default service("font-services/font-rebuild", serviceImplementation, true);
開發者ID:eez-open,項目名稱:studio,代碼行數:17,代碼來源:font-rebuild.ts

示例3: service

import { service } from "eez-studio-shared/service";

export default service("pdf-services/pdf-to-png", async (data: string) => {
    const pdfjsLib = require("../../libs/pdfjs/build/pdf.js");
    pdfjsLib.GlobalWorkerOptions.workerSrc = "../../libs/pdfjs/build/pdf.worker.js";

    var pdfDocument = await pdfjsLib.getDocument(data);

    var page = await pdfDocument.getPage(1);

    var viewport = page.getViewport(1.0);

    var canvas = document.createElement("canvas");
    canvas.height = viewport.height;
    canvas.width = viewport.width;

    var context = canvas.getContext("2d");

    var renderContext = {
        canvasContext: context,
        viewport: viewport
    };

    await page.render(renderContext);

    return canvas.toDataURL();
});
開發者ID:eez-open,項目名稱:studio,代碼行數:27,代碼來源:pdf-to-png.ts

示例4: require

    if (path.extname(data.relativeFilePath) == ".bdf") {
        const { extractBdfFont } = require("font-services/bdf") as typeof BdfModule;
        return extractBdfFont(
            data.name,
            data.absoluteFilePath,
            data.relativeFilePath,
            data.bpp,
            data.createGlyphs,
            data.fromEncoding,
            data.toEncoding,
            data.createBlankGlyphs || false
        );
    } else {
        const { extractFreeTypeFont } = require("font-services/freetype") as typeof FreeTypeModule;
        return extractFreeTypeFont(
            data.name,
            data.absoluteFilePath,
            data.relativeFilePath,
            data.bpp,
            data.size,
            data.threshold,
            data.createGlyphs,
            data.fromEncoding,
            data.toEncoding,
            data.createBlankGlyphs || false
        );
    }
}

export default service("font-services/font-extract", serviceImplementation, true);
開發者ID:eez-open,項目名稱:studio,代碼行數:30,代碼來源:font-extract.ts

示例5: async

import { service } from "eez-studio-shared/service";

import { db } from "eez-studio-shared/db";

interface Params {
    query: string;
    args: any[];
}

interface Result {
    err: any;
    rows: any[];
}

export default service<Params, Result>("db-services/query", async (inputParams: Params) => {
    try {
        const rows = db.prepare(inputParams.query).all(...inputParams.args);
        return {
            err: null,
            rows
        };
    } catch (err) {
        return {
            err,
            rows: []
        };
    }
});
開發者ID:eez-open,項目名稱:studio,代碼行數:28,代碼來源:query.ts


注:本文中的eez-studio-shared/service.service函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。