• WinJS.Binding Angkor:


    expandProperties: function (shape) { /// /// /// Wraps the specified object so that all its properties /// are instrumented for binding. This is meant to be used in /// conjunction with the binding mixin. /// ////// The specification for the bindable object. /// /// /// An object with a set of properties all of which are wired for binding. /// /// var props = {}; function addToProps(k) { props[k] = { get: function () { return this.getProperty(k); }, set: function (value) { this.setProperty(k, value); }, enumerable: true, configurable: true // enables delete }; } while (shape && shape !== Object.prototype) { Object.keys(shape).forEach(addToProps); shape = Object.getPrototypeOf(shape); } return props; }


    define: function (data) { /// /// /// Creates a new constructor function that supports observability with /// the specified set of properties. /// /// /// The object to use as the pattern for defining the set of properties, for example: /// var MyPointClass = define({x:0,y:0}); /// /// /// A constructor function with 1 optional argument that is the initial state of /// the properties. /// /// // Common unsupported types, we just coerce to be an empty record // if (!data || typeof (data) !== "object" || (data instanceof Date) || (data instanceof Array)) { if (WinJS.validation) { throw new WinJS.ErrorFromName("WinJS.Binding.UnsupportedDataType", WinJS.Resources._formatString(strings.unsupportedDataTypeForBinding)); } else { return; } } return WinJS.Class.mix( function (init) { /// /// /// Creates a new observable object. /// /// /// The initial values for the properties. /// /// this._initObservable(init || Object.create(data)); }, WinJS.Binding.dynamicObservableMixin, WinJS.Binding.expandProperties(data) ); }


    as: function (data) { /// /// /// Returns an observable object. This may be an observable proxy for the specified object, an existing proxy, or /// the specified object itself if it directly supports observability. /// /// /// Object to provide observability for. /// /// /// The observable object. /// /// if (!data) { return data; } var type = typeof data; if (type === "object" && !(data instanceof Date) && !(data instanceof Array)) { if (data._getObservable) { return data._getObservable(); } var observable = new ObservableProxy(data); observable.backingData = data; Object.defineProperty( data, "_getObservable", { value: function () { return observable; }, enumerable: false, writable: false } ); return observable; } else { return data; } }


    unwrap: function (data) { /// /// /// Returns the original (non-observable) object is returned if the specified object is an observable proxy, . /// /// /// The object for which to retrieve the original value. /// /// /// If the specified object is an observable proxy, the original object is returned, otherwise the same object is returned. /// /// if (data && data.backingData) return data.backingData; else return data; }


    bind: function (observable, bindingDescriptor) { /// /// /// Binds to one or more properties on the observable object or or on child values /// of that object. /// /// /// The object to bind to. /// /// /// An object literal containing the binding declarations. Binding declarations take the form: /// { propertyName: (function | bindingDeclaration), ... } /// /// For example, binding to a nested member of an object is declared like this: /// bind(someObject, { address: { street: function(v) { ... } } }); /// /// /// An object that contains at least a "cancel" field, which is /// a function that removes all bindings associated with this bind /// request. /// /// return bindImpl(observable, bindingDescriptor); }


    dynamicObservableMixin: [object Object]


    observableMixin: [object Object]


    Template: function Template_ctor(element, options) { /// /// /// Creates a template that provides a reusable declarative binding element. /// /// /// The DOM element to convert to a template. /// /// /// If this parameter is supplied, the template is loaded from the URI and /// the content of the element parameter is ignored. /// /// msWriteProfilerMark("WinJS.Binding:newTemplate,StartTM"); this._element = element = element || document.createElement("div"); var that = this; if (element) { element.renderItem = function (item, recycled) { return that.renderItem(item, recycled); }; } if (options) { this.href = options.href; this.enableRecycling = !!options.enableRecycling; if (options.processTimeout) { this.processTimeout = options.processTimeout; } } if (!this.href) { this.element.style.display = "none"; } this.bindingCache = { expressions: {} }; msWriteProfilerMark("WinJS.Binding:newTemplate,StopTM"); }


    processAll: function declarativeBind(rootElement, dataContext, skipRoot, bindingCache) { /// /// /// Binds values from the specified data context to elements that are descendants of the specified root element /// and have declarative binding attributes (data-win-bind). /// /// /// The element at which to start traversing to find elements to bind to. If this parameter is omitted, the entire document /// is searched. /// /// /// The object to use for default data binding. /// /// /// If true, the elements to be bound skip the specified root element and include only the children. /// /// /// The cached binding data. /// /// /// A promise that completes when each item that contains binding declarations has /// been processed and the update has started. /// /// return new WinJS.Promise(function (c, e, p) { declarativeBindImpl(rootElement, dataContext, skipRoot, bindingCache, c, e, p); }).then(null, function (e) { WinJS.log && WinJS.log(WinJS.Resources._formatString(strings.errorInitializingBindings, e && e.message), "winjs binding", "error"); return WinJS.Promise.wrapError(e); }); }


    oneTime: function oneTime(source, sourceProperties, dest, destProperties) { /// /// /// Sets the destination property to the value of the source property. /// /// /// The source object. /// /// /// The path on the source object to the source property. /// /// /// The destination object. /// /// /// The path on the destination object to the destination property. /// /// /// An object with a cancel method that is used to coalesce bindings. /// /// nestedSet(dest, destProperties, getValue(source, sourceProperties)); return { cancel: noop }; }


    defaultBind: function defaultBind(source, sourceProperties, dest, destProperties) { /// /// /// Creates a one-way binding between the source object and /// the destination object. /// /// /// The source object. /// /// /// The path on the source object to the source property. /// /// /// The destination object. /// /// /// The path on the destination object to the destination property. /// /// /// An object with a cancel method that is used to coalesce bindings. /// /// return defaultBindImpl(source, sourceProperties, dest, destProperties); }


    converter: function converter(convert) { /// /// /// Creates a default binding initializer for binding between a source /// property and a destination property with a provided converter function /// that is executed on the value of the source property. /// /// /// The conversion that operates over the result of the source property /// to produce a value that is set to the destination property. /// /// /// The binding initializer. /// /// var userConverter = function (source, sourceProperties, dest, destProperties) { var ref = dest.id; var bindingId = setBindingToken(dest); if (!ref) { uid++; if (optimizeBindingReferences) { ref = bindingId; } else { dest.id = ref = bindingId; } } WinJS.Utilities._createWeakRef(dest, ref); var workerResult = bindWorker(WinJS.Binding.as(source), sourceProperties, function (v) { var found = checkBindingToken(WinJS.Utilities._getWeakRefElement(ref), bindingId); if (found) { nestedSet(found, destProperties, convert(requireSupportedForProcessing(v))); } else if (workerResult) { WinJS.log && WinJS.log(WinJS.Resources._formatString(strings.elementNotFound, ref), "winjs binding", "info"); workerResult.cancel(); } }); return workerResult; }; return markSupportedForProcessing(userConverter); }


    initializer: function initializer(customInitializer) { /// /// /// Marks a custom initializer function as being compatible with declarative data binding. /// /// /// The custom initializer to be marked as compatible with declarative data binding. /// /// /// The input customInitializer. /// /// return markSupportedForProcessing(customInitializer); }


    setAttribute: function setAttribute(source, sourceProperties, dest, destProperties) { /// /// /// Creates a one-way binding between the source object and /// an attribute on the destination element. /// /// /// The source object. /// /// /// The path on the source object to the source property. /// /// /// The destination object (must be a DOM element). /// /// /// The path on the destination object to the destination property, this must be a single name. /// /// /// An object with a cancel method that is used to coalesce bindings. /// /// var ref = dest.id; var bindingId = setBindingToken(dest); if (!ref) { uid++; if (optimizeBindingReferences) { ref = bindingId; } else { dest.id = ref = bindingId; } } WinJS.Utilities._createWeakRef(dest, ref); var workerResult = bindWorker(WinJS.Binding.as(source), sourceProperties, function (v) { var found = checkBindingToken(WinJS.Utilities._getWeakRefElement(ref), bindingId); if (found) { attributeSet(found, destProperties, requireSupportedForProcessing(v)); } else if (workerResult) { WinJS.log && WinJS.log(WinJS.Resources._formatString(strings.elementNotFound, ref), "winjs binding", "info"); workerResult.cancel(); } }); return workerResult; }


    setAttributeOneTime: function setAttributeOneTime(source, sourceProperties, dest, destProperties) { /// /// /// Sets an attribute on the destination element to the value of the source property /// /// /// The source object. /// /// /// The path on the source object to the source property. /// /// /// The destination object (must be a DOM element). /// /// /// The path on the destination object to the destination property, this must be a single name. /// /// return attributeSet(dest, destProperties, getValue(source, sourceProperties)); }


    optimizeBindingReferences: true


    List: function (list, options) { /// /// /// Creates a WinJS.Binding.List object. /// ///The array containing the elements to initalize the list. ///If options.binding is true, the list will contain the result of calling WinJS.Binding.as() on the element values. If options.proxy is true, the list specified as the first parameter is used as the storage for the WinJS.Binding.List. This option should be used with care because uncoordinated edits to the data storage will result in errors. /// The newly-constructed WinJS.Binding.List instance. /// this._currentKey = 0; this._keys = null; this._keyMap = {}; // options: // - binding: binding.as on items // - proxy: proxy over input data // options = options || emptyOptions; this._proxy = options.proxy; this._binding = options.binding; if (this._proxy) { if (Object.keys(list).length !== list.length) { throw new WinJS.ErrorFromName("WinJS.Binding.List.NotSupported", strings.sparseArrayNotSupported); } this._data = list; this._currentKey = list.length; } else if (list) { var keyDataMap = this._keyMap; var pos = 0, i = 0; for (var len = list.length; i < len; i++) { if (i in list) { var item = list[i]; if (this._binding) { item = WinJS.Binding.as(item); } var key = pos.toString(); pos++; keyDataMap[key] = { handle: key, key: key, data: item }; } } if (pos !== i) { this._initializeKeys(); } this._currentKey = pos; } }


  • 相关阅读:
    Python学习笔记:pandas.read_csv分块读取大文件(chunksize、iterator=True)
    Python学习笔记:os.stat().st_size、os.path.getsize()获取文件大小
    7-1 打印沙漏
    7-1 币值转换
    7-1 抓老鼠啊~亏了还是赚了?
    第四周编程总结哦也
    2018秋寒假作业6—PTA编程总结3
    PTA编程总结3
    PTA编程总结1
    秋季学期学习总结
  • 原文地址:https://www.cnblogs.com/wujiakun/p/2839453.html
Copyright © 2020-2023  润新知