当前位置: 首页>>代码示例>>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;未经允许,请勿转载。