Skip to content

Commit ddd99de

Browse files
authored
Merge pull request #253 from wechat-miniprogram/feat-make-properties-public
Make some properties public & hide private properties
2 parents 612e8de + 0273c24 commit ddd99de

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

glass-easel/src/behavior.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@ export class BehaviorBuilder<
140140
TPendingChainingFilter extends ChainingFilterType = never,
141141
TExtraThisFields extends DataList = Empty,
142142
> {
143+
public is: string | undefined
143144
/** @internal */
144145
_$ownerSpace: ComponentSpace
145146
/** @internal */
146-
_$is: string | undefined
147-
/** @internal */
148147
_$behaviors: (string | GeneralBehavior)[] = []
149148
/** @internal */
150149
_$chainingFilter?: (chain: GeneralBehaviorBuilder) => any
@@ -193,7 +192,7 @@ export class BehaviorBuilder<
193192

194193
/** @internal */
195194
constructor(is: string | undefined, ownerSpace: ComponentSpace) {
196-
this._$is = is
195+
this.is = is
197196
this._$ownerSpace = ownerSpace
198197
}
199198

@@ -370,7 +369,7 @@ export class BehaviorBuilder<
370369
>,
371370
TChainingFilter
372371
> {
373-
this._$data.push(() => safeCallback('Data Generator', gen, null, [], this._$is) ?? {})
372+
this._$data.push(() => safeCallback('Data Generator', gen, null, [], this.is) ?? {})
374373
return this as any
375374
}
376375

@@ -494,7 +493,7 @@ export class BehaviorBuilder<
494493
this._$observers.push({ dataPaths: parseMultiPaths(paths as string | string[]), func, once })
495494
} catch (e) {
496495
// parse multi paths my throw errors
497-
dispatchError(e, `observer`, this._$is)
496+
dispatchError(e, `observer`, this.is)
498497
}
499498
return this as any
500499
}
@@ -619,7 +618,7 @@ export class BehaviorBuilder<
619618
const rawData = def.data
620619
if (rawData !== undefined) {
621620
if (typeof rawData === 'function') {
622-
this._$data.push(() => safeCallback('Data Generator', rawData, null, [], this._$is) ?? {})
621+
this._$data.push(() => safeCallback('Data Generator', rawData, null, [], this.is) ?? {})
623622
} else {
624623
this._$staticData = rawData
625624
}
@@ -657,7 +656,7 @@ export class BehaviorBuilder<
657656
})
658657
} catch (e) {
659658
// parse multi paths may throw errors
660-
dispatchError(e, `definition`, this._$is)
659+
dispatchError(e, `definition`, this.is)
661660
}
662661
}
663662
} else {
@@ -673,7 +672,7 @@ export class BehaviorBuilder<
673672
})
674673
} catch (e) {
675674
// parse multi paths may throw errors
676-
dispatchError(e, `definition`, this._$is)
675+
dispatchError(e, `definition`, this.is)
677676
}
678677
}
679678
}
@@ -745,7 +744,7 @@ export class BehaviorBuilder<
745744
TPendingChainingFilter,
746745
TExtraThisFields
747746
> {
748-
const is = this._$is
747+
const is = this.is
749748
const behavior = new Behavior(this)
750749
if (is !== undefined) {
751750
this._$ownerSpace._$registerBehavior(is, behavior as unknown as GeneralBehavior)
@@ -772,11 +771,11 @@ export class BehaviorBuilder<
772771
* Finish build, generate a component definition, and register it in the component space
773772
*/
774773
registerComponent(): ComponentDefinition<TData, TProperty, TMethod> {
775-
const is = this._$is
774+
const is = this.is
776775
const behavior = new Behavior(this)
777776
const compDef = new ComponentDefinition(behavior)
778777
if (is !== undefined) {
779-
this._$ownerSpace._$registerComponent(is, compDef as unknown as GeneralComponentDefinition)
778+
this._$ownerSpace.registerComponent(is, compDef as unknown as GeneralComponentDefinition)
780779
}
781780
return compDef
782781
}
@@ -878,7 +877,7 @@ export class Behavior<
878877
>,
879878
) {
880879
this._$unprepared = true
881-
this.is = builder._$is || ''
880+
this.is = builder.is || ''
882881
this.ownerSpace = builder._$ownerSpace
883882
this._$builder = builder
884883
this._$flatAncestors = new Set()

glass-easel/src/component_space.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ export class ComponentSpace {
415415
return new BehaviorBuilder(is, this)
416416
}
417417

418-
/** @internal */
419-
_$registerComponent(is: string, comp: GeneralComponentDefinition) {
418+
/** Register a component in this space using an existing definition */
419+
registerComponent(is: string, comp: GeneralComponentDefinition) {
420420
this._$list[is] = comp
421421
this._$behaviorList[is] = comp.behavior as unknown as GeneralBehavior
422422
const waiting = this._$listWaiting[is]

glass-easel/src/data_proxy.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,25 +495,38 @@ export class DataGroup<
495495
> {
496496
data: DataWithPropertyValues<TData, TProperty>
497497
innerData: { [key: string]: DataValue } | null
498+
/* @internal */
498499
private _$comp: ComponentInstance<TData, TProperty, TMethod> | null
500+
/* @internal */
499501
private _$pureDataPattern: RegExp | null
502+
/* @internal */
500503
private _$dataDeepCopy: DeepCopyStrategy
504+
/* @internal */
501505
private _$propertyPassingDeepCopy: DeepCopyStrategy
506+
/* @internal */
502507
private _$reflectToAttributes: boolean
508+
/* @internal */
503509
private _$propFields: { [name: string]: PropertyDefinition }
504510
/** @internal */
505511
_$observerTree: DataGroupObserverTree
512+
/* @internal */
506513
private _$observerStatus: boolean[]
514+
/* @internal */
507515
private _$modelBindingListener: { [name: string]: ModelBindingListener } | null = null
516+
/* @internal */
508517
private _$updateListener?: DataUpdateCallback
518+
/* @internal */
509519
private _$pendingChanges: DataChange[] = []
520+
/* @internal */
510521
private _$doingUpdates: {
511522
prop: PropertyChange[]
512523
combined: DataChange[]
513524
count: number
514525
} | null = null
526+
/* @internal */
515527
private _$recUpdateLevel = 0
516528

529+
/* @internal */
517530
private _$generateInnerData(data: { [key: string]: DataValue }) {
518531
const pureDataPattern = this._$pureDataPattern
519532
const dataDeepCopy = this._$dataDeepCopy

glass-easel/src/mutation_observer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export type MutationObserverEvent =
8787
export type MutationObserverListener<T> = (this: Node, ev: T) => void
8888

8989
export class MutationObserverTarget {
90+
/* @internal */
9091
private _$bound: Node
92+
/* @internal */
9193
private _$subtreeObserversCount = 0
9294
attrObservers: FuncArr<MutationObserverListener<MutationObserverAttrEvent>> | null = null
9395
allAttrObservers: FuncArr<MutationObserverListener<MutationObserverAttrEvent>> | null = null
@@ -190,10 +192,15 @@ export class MutationObserverTarget {
190192
* Further more, it can listen attached/detached events on an element.
191193
*/
192194
export class MutationObserver {
195+
/* @internal */
193196
private _$listener: MutationObserverListener<MutationObserverEvent> | null
197+
/* @internal */
194198
private _$normalizedListener: MutationObserverListener<MutationObserverEvent> | null
199+
/* @internal */
195200
private _$subtreeListenersCount = 0
201+
/* @internal */
196202
private _$boundFuncArrs: FuncArr<MutationObserverListener<MutationObserverEvent>>[] = []
203+
/* @internal */
197204
private _$boundTarget: MutationObserverTarget | null = null
198205

199206
constructor(listener: (ev: MutationObserverEvent) => void) {

0 commit comments

Comments
 (0)