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


TypeScript utils.extend方法代碼示例

本文整理匯總了TypeScript中knockout.utils.extend方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript utils.extend方法的具體用法?TypeScript utils.extend怎麽用?TypeScript utils.extend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在knockout.utils的用法示例。


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

示例1: function

function history<T>(initialValue?: T): history.HistoryObservable<T> {
    const self = {
        latestValues: ko.observableArray([initialValue]),
        selectedIndex: ko.observable(0),
        canGoBack: ko.pureComputed(() => self.selectedIndex() > 0),
        canGoNext: ko.pureComputed(() => self.selectedIndex() < self.latestValues().length - 1)
    } as any;

    ko.utils.extend(self, history.fn);

    const result: any = ko.pureComputed({
        read: () => {
            const values = self.latestValues();
            let index = self.selectedIndex();

            if (index > values.length) {
                index = 0;
            }

            return values[index];
        },
        write: (value: any) => {
            const
                index = self.selectedIndex(),
                values = self.latestValues();

            if (value !== values[index]) {
                if (index !== values.length - 1) {
                    values.splice(index + 1);
                }

                values.push(value);
                self.selectedIndex(index + 1);
            }
        }
    }).extend({ notify: "reference" });

    ko.utils.extend(result, self);

    const oldDispose = result.dispose;
    result.dispose = function () {
        oldDispose.call(this);
        this.canGoBack.dispose();
        this.canGoNext.dispose();
    };

    return result;
}
開發者ID:spatools,項目名稱:koutils,代碼行數:48,代碼來源:history.ts

示例2: function

    init: function (element, valueAccessor) {
        const $element = $(element);
        let value = valueAccessor(),
            options = ko.unwrap(value),
            id = $element.attr("id"),
            oldSetup, editor;

        if (typeof options === "object") {
            value = options.value;
            delete options.value;
        }
        else {
            options = {};
        }

        if (!id) {
            id = tinymce.DOM.uniqueId();
            $element.attr("id", id);
        }

        ko.utils.extend(options, defaults);

        oldSetup = options.setup;
        options.setup = (editor) => {
            oldSetup && oldSetup.call(undefined, editor);
        };

        if ($element.is("textarea"))
            $element.val(ko.unwrap(value));
        else {
            $element.html(ko.unwrap(value));
            options.inline = true;
        }

        editor = new tinymce.Editor(id, options, tinymce.EditorManager);
        editor.on("change keyup nodechange", () => {
            if (ko.isWriteableObservable(value)) value(editor.getContent());
        });

        // To prevent a memory leak, ensure that the underlying element"s disposal destroys it"s associated editor.
        ko.utils.domNodeDisposal.addDisposeCallback(element, () => {
            if (editor) {
                editor.remove();
                editor = null;
            }
        });

        editor.render();
    },
開發者ID:spatools,項目名稱:koui,代碼行數:49,代碼來源:tinymce.ts

示例3: trigger

export function trigger(element: HTMLElement, eventType: string, eventArgs: any): void {
    let evt;
    if (doc.createEvent) {
        evt = doc.createEvent("HTMLEvents");
        evt.initEvent(eventType, true, true);
    } else {
        evt = doc.createEventObject();
        evt.eventType = eventType;
    }

    evt.eventName = eventType;
    ko.utils.extend(evt, eventArgs);

    if (doc.createEvent) {
        element.dispatchEvent(evt);
    } else {
        element.fireEvent("on" + evt.eventType, evt);
    }
}
開發者ID:spatools,項目名稱:koui,代碼行數:19,代碼來源:event.ts

示例4:

			crossroads.addRoute(route.url,(requestParams) => {
				this.currentRoute(ko.utils.extend(requestParams, route.params));
			});
開發者ID:robertsundstrom,項目名稱:express-knockout-spa,代碼行數:3,代碼來源:router.ts


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