mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
KnockoutJS drop unused as
This commit is contained in:
parent
513fc949d7
commit
dde1183174
4 changed files with 11 additions and 29 deletions
|
|
@ -13,7 +13,7 @@ ko.bindingHandlers = {};
|
||||||
// The ko.bindingContext constructor is only called directly to create the root context. For child
|
// The ko.bindingContext constructor is only called directly to create the root context. For child
|
||||||
// contexts, use bindingContext.createChildContext or bindingContext.extend.
|
// contexts, use bindingContext.createChildContext or bindingContext.extend.
|
||||||
ko.bindingContext = class {
|
ko.bindingContext = class {
|
||||||
constructor(dataItemOrAccessor, parentContext, dataItemAlias, extendCallback, options)
|
constructor(dataItemOrAccessor, parentContext, extendCallback, options)
|
||||||
{
|
{
|
||||||
var self = this,
|
var self = this,
|
||||||
shouldInheritData = dataItemOrAccessor === inheritParentVm,
|
shouldInheritData = dataItemOrAccessor === inheritParentVm,
|
||||||
|
|
@ -60,9 +60,6 @@ ko.bindingContext = class {
|
||||||
self['$data'] = dataItem;
|
self['$data'] = dataItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataItemAlias)
|
|
||||||
self[dataItemAlias] = dataItem;
|
|
||||||
|
|
||||||
// The extendCallback function is provided when creating a child context or extending a context.
|
// The extendCallback function is provided when creating a child context or extending a context.
|
||||||
// It handles the specific actions needed to finish setting up the binding context. Actions in this
|
// It handles the specific actions needed to finish setting up the binding context. Actions in this
|
||||||
// function could also add dependencies to this binding context.
|
// function could also add dependencies to this binding context.
|
||||||
|
|
@ -107,21 +104,14 @@ ko.bindingContext = class {
|
||||||
// But this does not mean that the $data value of the child context will also get updated. If the child
|
// But this does not mean that the $data value of the child context will also get updated. If the child
|
||||||
// view model also depends on the parent view model, you must provide a function that returns the correct
|
// view model also depends on the parent view model, you must provide a function that returns the correct
|
||||||
// view model on each update.
|
// view model on each update.
|
||||||
'createChildContext'(dataItemOrAccessor, dataItemAlias, extendCallback, options) {
|
'createChildContext'(dataItemOrAccessor, options) {
|
||||||
if (!options && dataItemAlias && typeof dataItemAlias == "object") {
|
return new ko.bindingContext(dataItemOrAccessor, this, (self, parentContext) => {
|
||||||
options = dataItemAlias;
|
|
||||||
dataItemAlias = options['as'];
|
|
||||||
extendCallback = options['extend'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ko.bindingContext(dataItemOrAccessor, this, dataItemAlias, (self, parentContext) => {
|
|
||||||
// Extend the context hierarchy by setting the appropriate pointers
|
// Extend the context hierarchy by setting the appropriate pointers
|
||||||
self['$parentContext'] = parentContext;
|
self['$parentContext'] = parentContext;
|
||||||
self['$parent'] = parentContext['$data'];
|
self['$parent'] = parentContext['$data'];
|
||||||
self['$parents'] = (parentContext['$parents'] || []).slice(0);
|
self['$parents'] = (parentContext['$parents'] || []).slice(0);
|
||||||
self['$parents'].unshift(self['$parent']);
|
self['$parents'].unshift(self['$parent']);
|
||||||
if (extendCallback)
|
options['extend']?.(self);
|
||||||
extendCallback(self);
|
|
||||||
}, options);
|
}, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,7 +119,7 @@ ko.bindingContext = class {
|
||||||
// Similarly to "child" contexts, provide a function here to make sure that the correct values are set
|
// Similarly to "child" contexts, provide a function here to make sure that the correct values are set
|
||||||
// when an observable view model is updated.
|
// when an observable view model is updated.
|
||||||
'extend'(properties, options) {
|
'extend'(properties, options) {
|
||||||
return new ko.bindingContext(inheritParentVm, this, null, self =>
|
return new ko.bindingContext(inheritParentVm, this, self =>
|
||||||
ko.utils.extend(self, typeof(properties) == "function" ? properties(self) : properties)
|
ko.utils.extend(self, typeof(properties) == "function" ? properties(self) : properties)
|
||||||
, options);
|
, options);
|
||||||
}
|
}
|
||||||
|
|
@ -432,7 +422,7 @@ ko.storedBindingContextForNode = node => {
|
||||||
function getBindingContext(viewModelOrBindingContext, extendContextCallback) {
|
function getBindingContext(viewModelOrBindingContext, extendContextCallback) {
|
||||||
return viewModelOrBindingContext && (viewModelOrBindingContext instanceof ko.bindingContext)
|
return viewModelOrBindingContext && (viewModelOrBindingContext instanceof ko.bindingContext)
|
||||||
? viewModelOrBindingContext
|
? viewModelOrBindingContext
|
||||||
: new ko.bindingContext(viewModelOrBindingContext, undefined, undefined, extendContextCallback);
|
: new ko.bindingContext(viewModelOrBindingContext, null, extendContextCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
ko['applyBindingAccessorsToNode'] = (node, bindings, viewModelOrBindingContext) =>
|
ko['applyBindingAccessorsToNode'] = (node, bindings, viewModelOrBindingContext) =>
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ ko.bindingHandlers['foreach'] = {
|
||||||
// If unwrappedValue.data is the array, preserve all relevant options and unwrap again value so we get updates
|
// If unwrappedValue.data is the array, preserve all relevant options and unwrap again value so we get updates
|
||||||
ko.utils.unwrapObservable(modelValue);
|
ko.utils.unwrapObservable(modelValue);
|
||||||
return {
|
return {
|
||||||
'foreach': unwrappedValue['data'],
|
'foreach': unwrappedValue['data']
|
||||||
'as': unwrappedValue['as']
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'init': (element, valueAccessor) =>
|
'init': (element, valueAccessor) =>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ function makeWithIfBinding(bindingKey, isWith, isNot) {
|
||||||
var savedNodes, contextOptions = {}, needAsyncContext;
|
var savedNodes, contextOptions = {}, needAsyncContext;
|
||||||
|
|
||||||
if (isWith) {
|
if (isWith) {
|
||||||
contextOptions = { 'as': allBindings.get('as'), 'exportDependencies': true };
|
contextOptions = { 'exportDependencies': true };
|
||||||
}
|
}
|
||||||
|
|
||||||
needAsyncContext = allBindings['has'](ko.bindingEvent.descendantsComplete);
|
needAsyncContext = allBindings['has'](ko.bindingEvent.descendantsComplete);
|
||||||
|
|
|
||||||
13
vendors/knockout/src/templating/templating.js
vendored
13
vendors/knockout/src/templating/templating.js
vendored
|
|
@ -115,7 +115,7 @@
|
||||||
// Ensure we've got a proper binding context to work with
|
// Ensure we've got a proper binding context to work with
|
||||||
var bindingContext = (dataOrBindingContext instanceof ko.bindingContext)
|
var bindingContext = (dataOrBindingContext instanceof ko.bindingContext)
|
||||||
? dataOrBindingContext
|
? dataOrBindingContext
|
||||||
: new ko.bindingContext(dataOrBindingContext, null, null, null, { "exportDependencies": true });
|
: new ko.bindingContext(dataOrBindingContext, null, null, { "exportDependencies": true });
|
||||||
|
|
||||||
var templateName = resolveTemplateName(template, bindingContext['$data'], bindingContext);
|
var templateName = resolveTemplateName(template, bindingContext['$data'], bindingContext);
|
||||||
executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options);
|
executeTemplate(targetNodeOrNodeArray, renderMode, templateName, bindingContext, options);
|
||||||
|
|
@ -130,19 +130,13 @@
|
||||||
ko.renderTemplateForEach = (template, arrayOrObservableArray, options, targetNode, parentBindingContext) => {
|
ko.renderTemplateForEach = (template, arrayOrObservableArray, options, targetNode, parentBindingContext) => {
|
||||||
// Since setDomNodeChildrenFromArrayMapping always calls executeTemplateForArrayItem and then
|
// Since setDomNodeChildrenFromArrayMapping always calls executeTemplateForArrayItem and then
|
||||||
// activateBindingsCallback for added items, we can store the binding context in the former to use in the latter.
|
// activateBindingsCallback for added items, we can store the binding context in the former to use in the latter.
|
||||||
var arrayItemContext, asName = options['as'];
|
var arrayItemContext;
|
||||||
|
|
||||||
// This will be called by setDomNodeChildrenFromArrayMapping to get the nodes to add to targetNode
|
// This will be called by setDomNodeChildrenFromArrayMapping to get the nodes to add to targetNode
|
||||||
var executeTemplateForArrayItem = (arrayValue, index) => {
|
var executeTemplateForArrayItem = (arrayValue, index) => {
|
||||||
// Support selecting template as a function of the data being rendered
|
// Support selecting template as a function of the data being rendered
|
||||||
arrayItemContext = parentBindingContext['createChildContext'](arrayValue, {
|
arrayItemContext = parentBindingContext['createChildContext'](arrayValue, {
|
||||||
'as': asName,
|
'extend': context => context['$index'] = index
|
||||||
'extend': context => {
|
|
||||||
context['$index'] = index;
|
|
||||||
if (asName) {
|
|
||||||
context[asName + "Index"] = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var templateName = resolveTemplateName(template, arrayValue, arrayItemContext);
|
var templateName = resolveTemplateName(template, arrayValue, arrayItemContext);
|
||||||
|
|
@ -267,7 +261,6 @@
|
||||||
var innerBindingContext = bindingContext;
|
var innerBindingContext = bindingContext;
|
||||||
if ('data' in options) {
|
if ('data' in options) {
|
||||||
innerBindingContext = bindingContext['createChildContext'](options['data'], {
|
innerBindingContext = bindingContext['createChildContext'](options['data'], {
|
||||||
'as': options['as'],
|
|
||||||
'exportDependencies': true
|
'exportDependencies': true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue