mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 14:07:04 +03:00
Dropped more unused knockoutjs code
This commit is contained in:
parent
b79d9de1a0
commit
1d57a62ddd
14 changed files with 408 additions and 635 deletions
|
|
@ -1,82 +0,0 @@
|
|||
(() => {
|
||||
// Overridable API for determining which component name applies to a given node. By overriding this,
|
||||
// you can for example map specific tagNames to components that are not preregistered.
|
||||
ko.components['getComponentNameForNode'] = node => {
|
||||
var tagNameLower = ko.utils.tagNameLower(node);
|
||||
if (ko.components.isRegistered(tagNameLower)) {
|
||||
// Try to determine that this node can be considered a *custom* element; see https://github.com/knockout/knockout/issues/1603
|
||||
if (tagNameLower.indexOf('-') != -1 || ('' + node) == "[object HTMLUnknownElement]") {
|
||||
return tagNameLower;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ko.components.addBindingsForCustomElement = (allBindings, node, bindingContext, valueAccessors) => {
|
||||
// Determine if it's really a custom element matching a component
|
||||
if (node.nodeType === 1) {
|
||||
var componentName = ko.components['getComponentNameForNode'](node);
|
||||
if (componentName) {
|
||||
// It does represent a component, so add a component binding for it
|
||||
allBindings = allBindings || {};
|
||||
|
||||
if (allBindings['component']) {
|
||||
// Avoid silently overwriting some other 'component' binding that may already be on the element
|
||||
throw new Error('Cannot use the "component" binding on a custom element matching a component');
|
||||
}
|
||||
|
||||
var componentBindingValue = { 'name': componentName, 'params': getComponentParamsFromCustomElement(node, bindingContext) };
|
||||
|
||||
allBindings['component'] = valueAccessors
|
||||
? () => componentBindingValue
|
||||
: componentBindingValue;
|
||||
}
|
||||
}
|
||||
|
||||
return allBindings;
|
||||
}
|
||||
|
||||
var nativeBindingProviderInstance = new ko.bindingProvider();
|
||||
|
||||
function getComponentParamsFromCustomElement(elem, bindingContext) {
|
||||
var paramsAttribute = elem.getAttribute('params');
|
||||
|
||||
if (paramsAttribute) {
|
||||
var params = nativeBindingProviderInstance['parseBindingsString'](paramsAttribute, bindingContext, elem, { 'valueAccessors': true, 'bindingParams': true }),
|
||||
rawParamComputedValues = ko.utils.objectMap(params, paramValue =>
|
||||
ko.computed(paramValue, null, { disposeWhenNodeIsRemoved: elem })
|
||||
),
|
||||
result = ko.utils.objectMap(rawParamComputedValues, paramValueComputed => {
|
||||
var paramValue = paramValueComputed.peek();
|
||||
// Does the evaluation of the parameter value unwrap any observables?
|
||||
if (!paramValueComputed.isActive()) {
|
||||
// No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.
|
||||
// Example: "someVal: firstName, age: 123" (whether or not firstName is an observable/computed)
|
||||
return paramValue;
|
||||
} else {
|
||||
// Yes it does. Supply a computed property that unwraps both the outer (binding expression)
|
||||
// level of observability, and any inner (resulting model value) level of observability.
|
||||
// This means the component doesn't have to worry about multiple unwrapping. If the value is a
|
||||
// writable observable, the computed will also be writable and pass the value on to the observable.
|
||||
return ko.computed({
|
||||
'read': () => ko.utils.unwrapObservable(paramValueComputed()),
|
||||
'write': ko.isWriteableObservable(paramValue) && (value => paramValueComputed()(value)),
|
||||
disposeWhenNodeIsRemoved: elem
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Give access to the raw computeds, as long as that wouldn't overwrite any custom param also called '$raw'
|
||||
// This is in case the developer wants to react to outer (binding) observability separately from inner
|
||||
// (model value) observability, or in case the model value observable has subobservables.
|
||||
if (!Object.prototype.hasOwnProperty.call(result, '$raw')) {
|
||||
result['$raw'] = rawParamComputedValues;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
// For consistency, absence of a "params" attribute is treated the same as the presence of
|
||||
// any empty one. Otherwise component viewmodels need special code to check whether or not
|
||||
// 'params' or 'params.$raw' is null/undefined before reading subproperties, which is annoying.
|
||||
return { '$raw': {} };
|
||||
}
|
||||
})();
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
}
|
||||
|
||||
function cloneNodesFromTemplateSourceElement(elemInstance) {
|
||||
if ('template' == ko.utils.tagNameLower(elemInstance)) {
|
||||
if (elemInstance.matches('TEMPLATE')) {
|
||||
// For browsers with proper <template> element support (i.e., where the .content property
|
||||
// gives a document fragment), use that document fragment.
|
||||
if (elemInstance.content instanceof DocumentFragment) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue