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


TypeScript knockout.pureComputed函數代碼示例

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


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

示例1: createToggleButton

 export function createToggleButton(title = "Toggle") {
     const toggled = ko.observable(Math.random() >= 0.5);
     
     return {
         __: "button",
         title: ko.pureComputed(() => title + (toggled() ? " (on)" : " (off)")), 
         icon: getRandomIcon(),
         selected: toggled,
         click: function() { toggled(!toggled()); }
     };
 }
開發者ID:spatools,項目名稱:koui,代碼行數:11,代碼來源:ribbon.ts

示例2: constructor

 constructor(public question: QuestionBase) {
     var self = this;
     question.visibilityChangedCallback = function () { self.onVisibilityChanged(); };
     question.renderWidthChangedCallback = function () { self.onRenderWidthChanged(); };
     this.koVisible = ko.observable(this.question.visible);
     this.koRenderWidth = ko.observable(this.question.renderWidth);
     this.koErrors = ko.observableArray();
     this.koMarginLeft = ko.pureComputed(function () { self.koRenderWidth(); return self.getIndentSize(self.question.indent); });
     this.koPaddingRight = ko.observable(self.getIndentSize(self.question.rightIndent));
     this.question["koVisible"] = this.koVisible;
     this.question["koRenderWidth"] = this.koRenderWidth;
     this.question["koErrors"] = this.koErrors;
     this.question["koMarginLeft"] = this.koMarginLeft;
     this.question["koPaddingRight"] = this.koPaddingRight;
 }
開發者ID:mirmdasif,項目名稱:surveyjs,代碼行數:15,代碼來源:koquestionbase.ts

示例3:

export function createComputedArray<T>(value: MaybeSubscribable<any[]>, mapFunction?: (obj: any) => T, context?: any): ko.PureComputed<T[]> {
    const cpArray = ko.pureComputed(() => {
        if (cpArray[OLD_VALUES_PROPERTY]) {
            cpArray[OLD_VALUES_PROPERTY].forEach(d => { 
                if (typeof d.dispose === "function") {
                    d.dispose();
                }
            });
        }
        
        const val = ko.unwrap(value);
        if (!Array.isArray(val)) {
            cpArray[OLD_VALUES_PROPERTY] = null;
            return [];
        }
        
        return cpArray[OLD_VALUES_PROPERTY] = val.map(mapFunction, context);
    });
    
    return cpArray;
}
開發者ID:spatools,項目名稱:koui,代碼行數:21,代碼來源:utils.ts

示例4: purify

export function unpromise<T>(evaluator: () => T | PromiseLike<T>, options?: UnpromiseOptions<T>): ko.PureComputed<T | undefined> {
    options = options || {};

    const
        latestValue = ko.observable(options.initialValue),
        errorValue = options.errorValue || options.initialValue,
        owner = options.owner,

        pureComputed = ko.pureComputed<T | undefined>(latestValue);

    let waitingOn = 0;

    purify(pureComputed, function () {
        var prom = evaluator.call(owner),
            current = ++waitingOn;

        if (isPromiseLike(prom)) {
            prom.then(
                res => {
                    if (current === waitingOn) {
                        latestValue(res);
                    }
                },
                () => {
                    if (current === waitingOn) {
                        latestValue(errorValue);
                    }
                });
        }
        else {
            latestValue(prom);
        }
    });

    return pureComputed;
}
開發者ID:spatools,項目名稱:koutils,代碼行數:36,代碼來源:purifier.ts

示例5: beforeEach

 beforeEach(() => {
     obs = ko.observable("value");
     base = ko.pureComputed<number>(ko.observable(Math.random()));
 });
開發者ID:spatools,項目名稱:koutils,代碼行數:4,代碼來源:purifier.ts

示例6: constructor

 constructor(data) {
     mapping.fromJS(data, {}, this);
     this.nameLength = ko.pureComputed(() => this.name().length, this);
 }
開發者ID:typed-contrib,項目名稱:knockout.mapping,代碼行數:4,代碼來源:test.ts


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