fix: refine type definitions and improve loop constructs for better clarity
This commit is contained in:
parent
afff93196a
commit
0ce566f502
24
src/main.ts
24
src/main.ts
|
@ -38,7 +38,7 @@ export default (options: ComponentOptions) => {
|
||||||
private _states: Record<string, any> = {}
|
private _states: Record<string, any> = {}
|
||||||
private _stateToElementsMap: Record<string, Set<HTMLElement>> = {}
|
private _stateToElementsMap: Record<string, Set<HTMLElement>> = {}
|
||||||
private _currentRenderingElement: HTMLElement | null = null
|
private _currentRenderingElement: HTMLElement | null = null
|
||||||
private _statesListeners: Record<string, Function> = {}
|
private _statesListeners: Record<string, (...args: any[]) => void> = {}
|
||||||
private _textBindings: Array<{
|
private _textBindings: Array<{
|
||||||
node: Text
|
node: Text
|
||||||
expr: string
|
expr: string
|
||||||
|
@ -69,9 +69,9 @@ export default (options: ComponentOptions) => {
|
||||||
set: (target: Record<string, any>, keyPath: string, value: any) => {
|
set: (target: Record<string, any>, keyPath: string, value: any) => {
|
||||||
const valueRoute = keyPath.split('.')
|
const valueRoute = keyPath.split('.')
|
||||||
let currentTarget = target
|
let currentTarget = target
|
||||||
for (let i in valueRoute) {
|
for (const i in valueRoute) {
|
||||||
const key = valueRoute[i]
|
const key = valueRoute[i]
|
||||||
if (parseInt(i) === valueRoute.length - 1) {
|
if (Number.parseInt(i) === valueRoute.length - 1) {
|
||||||
currentTarget[key] = value
|
currentTarget[key] = value
|
||||||
} else {
|
} else {
|
||||||
if (!currentTarget[key]) {
|
if (!currentTarget[key]) {
|
||||||
|
@ -110,9 +110,9 @@ export default (options: ComponentOptions) => {
|
||||||
|
|
||||||
const valueRoute = keyPath.split('.')
|
const valueRoute = keyPath.split('.')
|
||||||
let currentTarget = target
|
let currentTarget = target
|
||||||
for (let i in valueRoute) {
|
for (const i in valueRoute) {
|
||||||
const key = valueRoute[i]
|
const key = valueRoute[i]
|
||||||
if (parseInt(i) === valueRoute.length - 1) {
|
if (Number.parseInt(i) === valueRoute.length - 1) {
|
||||||
return currentTarget[key]
|
return currentTarget[key]
|
||||||
} else {
|
} else {
|
||||||
if (!currentTarget[key]) {
|
if (!currentTarget[key]) {
|
||||||
|
@ -533,12 +533,12 @@ export default (options: ComponentOptions) => {
|
||||||
// Determine the key for this item
|
// Determine the key for this item
|
||||||
const key = keyAttr
|
const key = keyAttr
|
||||||
? this._evaluateExpressionWithItemContext(
|
? this._evaluateExpressionWithItemContext(
|
||||||
keyAttr ?? '',
|
keyAttr ?? '',
|
||||||
item,
|
item,
|
||||||
index,
|
index,
|
||||||
itemVar,
|
itemVar,
|
||||||
indexVar ? indexVar : undefined,
|
indexVar ? indexVar : undefined,
|
||||||
)
|
)
|
||||||
: index
|
: index
|
||||||
|
|
||||||
// Check if we can reuse an existing element
|
// Check if we can reuse an existing element
|
||||||
|
@ -624,7 +624,7 @@ export default (options: ComponentOptions) => {
|
||||||
itemContext: Record<string, any>,
|
itemContext: Record<string, any>,
|
||||||
) {
|
) {
|
||||||
// 1. Store the item context of the element so that subsequent updates can find it
|
// 1. Store the item context of the element so that subsequent updates can find it
|
||||||
;(element as any)._itemContext = itemContext
|
; (element as any)._itemContext = itemContext
|
||||||
|
|
||||||
// 2. Process bindings in text nodes
|
// 2. Process bindings in text nodes
|
||||||
const processTextNodes = (node: Node) => {
|
const processTextNodes = (node: Node) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user