@aurelia/runtime
Advanced tools
Comparing version 2.0.1-dev.202311120949 to 2.0.1-dev.202312050532
@@ -5,3 +5,3 @@ export { ExpressionKind, CallFunctionExpression, CustomExpression, BindingBehaviorExpression, ValueConverterExpression, AssignExpression, ConditionalExpression, AccessThisExpression, AccessGlobalExpression, AccessScopeExpression, AccessMemberExpression, AccessKeyedExpression, CallScopeExpression, CallMemberExpression, BinaryExpression, UnaryExpression, PrimitiveLiteralExpression, ArrayLiteralExpression, ObjectLiteralExpression, TemplateExpression, TaggedTemplateExpression, ArrayBindingPattern, ObjectBindingPattern, BindingIdentifier, ForOfStatement, Interpolation, DestructuringAssignmentExpression, DestructuringAssignmentSingleExpression, DestructuringAssignmentRestExpression, ArrowFunction, astVisit, Unparser, type AnyBindingExpression, type BindingBehaviorInstance, type IsPrimary, type IsLiteral, type IsLeftHandSide, type IsUnary, type IsBinary, type IsConditional, type IsAssign, type IsValueConverter, type IsBindingBehavior, type IsAssignable, type IsExpression, type IsExpressionOrStatement, type IVisitor, type BinaryOperator, type BindingIdentifierOrPattern, type UnaryOperator, type IAstEvaluator, type ValueConverterInstance, } from './binding/ast'; | ||
export { IExpressionParser, ExpressionType, parseExpression, } from './binding/expression-parser'; | ||
export { ArrayObserver, ArrayIndexObserver, enableArrayObservation, disableArrayObservation, applyMutationsToIndices, synchronizeIndices, type IArrayIndexObserver, } from './observation/array-observer'; | ||
export { ArrayObserver, ArrayIndexObserver, enableArrayObservation, disableArrayObservation, type IArrayIndexObserver, } from './observation/array-observer'; | ||
export { MapObserver, enableMapObservation, disableMapObservation, } from './observation/map-observer'; | ||
@@ -8,0 +8,0 @@ export { SetObserver, enableSetObservation, disableSetObservation } from './observation/set-observer'; |
@@ -37,15 +37,2 @@ import { AccessorType, type ISubscriberCollection, type ICollectionSubscriberCollection, type IObserver, type CollectionKind, type ICollectionObserver, type IndexMap, type ISubscriber } from '../observation'; | ||
export declare function getArrayObserver(array: unknown[]): ArrayObserver; | ||
/** | ||
* Applies offsets to the non-negative indices in the IndexMap | ||
* based on added and deleted items relative to those indices. | ||
* | ||
* e.g. turn `[-2, 0, 1]` into `[-2, 1, 2]`, allowing the values at the indices to be | ||
* used for sorting/reordering items if needed | ||
*/ | ||
export declare function applyMutationsToIndices(indexMap: IndexMap): IndexMap; | ||
/** | ||
* After `applyMutationsToIndices`, this function can be used to reorder items in a derived | ||
* array (e.g. the items in the `views` in the repeater are derived from the `items` property) | ||
*/ | ||
export declare function synchronizeIndices<T>(items: T[], indexMap: IndexMap): void; | ||
//# sourceMappingURL=array-observer.d.ts.map |
{ | ||
"name": "@aurelia/runtime", | ||
"version": "2.0.1-dev.202311120949", | ||
"version": "2.0.1-dev.202312050532", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -49,5 +49,5 @@ "module": "dist/esm/index.mjs", | ||
"dependencies": { | ||
"@aurelia/kernel": "2.0.1-dev.202311120949", | ||
"@aurelia/metadata": "2.0.1-dev.202311120949", | ||
"@aurelia/platform": "2.0.1-dev.202311120949" | ||
"@aurelia/kernel": "2.0.1-dev.202312050532", | ||
"@aurelia/metadata": "2.0.1-dev.202312050532", | ||
"@aurelia/platform": "2.0.1-dev.202312050532" | ||
}, | ||
@@ -54,0 +54,0 @@ "devDependencies": { |
@@ -81,4 +81,2 @@ export { | ||
disableArrayObservation, | ||
applyMutationsToIndices, | ||
synchronizeIndices, | ||
type IArrayIndexObserver, | ||
@@ -85,0 +83,0 @@ } from './observation/array-observer'; |
@@ -6,3 +6,2 @@ import { | ||
type ICollectionSubscriberCollection, | ||
cloneIndexMap, | ||
type IObserver, | ||
@@ -348,3 +347,3 @@ type CollectionKind, | ||
} | ||
if (shouldNotify) { | ||
if (shouldNotify || batching) { | ||
o.notify(); | ||
@@ -513,60 +512,1 @@ } | ||
} | ||
/** | ||
* A compare function to pass to `Array.prototype.sort` for sorting numbers. | ||
* This is needed for numeric sort, since the default sorts them as strings. | ||
*/ | ||
const compareNumber = (a: number, b: number): number => a - b; | ||
/** | ||
* Applies offsets to the non-negative indices in the IndexMap | ||
* based on added and deleted items relative to those indices. | ||
* | ||
* e.g. turn `[-2, 0, 1]` into `[-2, 1, 2]`, allowing the values at the indices to be | ||
* used for sorting/reordering items if needed | ||
*/ | ||
export function applyMutationsToIndices(indexMap: IndexMap): IndexMap { | ||
let offset = 0; | ||
let j = 0; | ||
let i = 0; | ||
const $indexMap = cloneIndexMap(indexMap); | ||
// during a batch, items could be deleted in a non-linear order with multiple splices | ||
if ($indexMap.deletedIndices.length > 1) { | ||
// TODO: also synchronize deletedItems when we need them | ||
$indexMap.deletedIndices.sort(compareNumber); | ||
} | ||
const len = $indexMap.length; | ||
for (; i < len; ++i) { | ||
while ($indexMap.deletedIndices[j] <= i - offset) { | ||
++j; | ||
--offset; | ||
} | ||
if ($indexMap[i] === -2) { | ||
++offset; | ||
} else { | ||
$indexMap[i] += offset; | ||
} | ||
} | ||
return $indexMap; | ||
} | ||
/** | ||
* After `applyMutationsToIndices`, this function can be used to reorder items in a derived | ||
* array (e.g. the items in the `views` in the repeater are derived from the `items` property) | ||
*/ | ||
export function synchronizeIndices<T>(items: T[], indexMap: IndexMap): void { | ||
const copy = items.slice(); | ||
const len = indexMap.length; | ||
let to = 0; | ||
let from = 0; | ||
while (to < len) { | ||
from = indexMap[to]; | ||
if (from !== -2) { | ||
items[to] = copy[from]; | ||
} | ||
++to; | ||
} | ||
} |
@@ -84,2 +84,4 @@ import { | ||
currBatch!.set(subs, [2, collection, indexMap]); | ||
} else { | ||
currBatch!.get(subs)![2] = indexMap; | ||
} | ||
@@ -86,0 +88,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1906830
34137
+ Added@aurelia/kernel@2.0.1-dev.202312050532(transitive)
+ Added@aurelia/metadata@2.0.1-dev.202312050532(transitive)
+ Added@aurelia/platform@2.0.1-dev.202312050532(transitive)
- Removed@aurelia/kernel@2.0.1-dev.202311120949(transitive)
- Removed@aurelia/metadata@2.0.1-dev.202311120949(transitive)
- Removed@aurelia/platform@2.0.1-dev.202311120949(transitive)