glass-easel-miniprogram-adapter 0.15.4 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -35,6 +35,7 @@ export type ComponentDefinitionOptions = {
35
35
  dataDeepCopy?: DeepCopyKind
36
36
  propertyPassingDeepCopy?: DeepCopyKind
37
37
  propertyEarlyInit?: boolean
38
+ propertyComparer?: (a: any, b: any) => boolean
38
39
  }
39
40
 
40
41
  type ComponentMethod = utils.ComponentMethod
@@ -662,6 +662,62 @@ describe('define', () => {
662
662
  expect(callOrder).toStrictEqual([1])
663
663
  })
664
664
 
665
+ test('options propertyComparer', () => {
666
+ const env = new MiniProgramEnv()
667
+ const codeSpace = env.createCodeSpace('', true)
668
+ let execArr: string[] = []
669
+
670
+ codeSpace.addCompiledTemplate(
671
+ 'child/comp',
672
+ tmpl(`
673
+ <div>{{a}}</div>
674
+ `),
675
+ )
676
+
677
+ codeSpace.componentEnv('child/comp', ({ Component }) =>
678
+ Component()
679
+ .property('a', { type: Number, value: 123 })
680
+ .observer('a', () => {
681
+ execArr.push('a')
682
+ })
683
+ .register(),
684
+ )
685
+
686
+ codeSpace.addCompiledTemplate(
687
+ 'path/to/comp',
688
+ tmpl(`
689
+ <child a="{{a}}" />
690
+ `),
691
+ )
692
+
693
+ codeSpace.addComponentStaticConfig('path/to/comp', {
694
+ usingComponents: {
695
+ child: '/child/comp',
696
+ },
697
+ })
698
+
699
+ codeSpace.componentEnv('path/to/comp', ({ Component }) =>
700
+ Component()
701
+ .options({
702
+ propertyComparer: (a: unknown, b: unknown) => a !== b,
703
+ })
704
+ .property('a', { type: Number, value: 123 })
705
+ .register(),
706
+ )
707
+
708
+ const ab = env.associateBackend()
709
+ const root = ab.createRoot('body', codeSpace, 'path/to/comp')
710
+ const rootComp = root.getComponent()
711
+
712
+ expect(execArr).toEqual(['a'])
713
+ execArr = []
714
+ rootComp.setData({ a: 233 })
715
+ expect(execArr).toEqual(['a'])
716
+ execArr = []
717
+ rootComp.setData({ a: 233 })
718
+ expect(execArr).toEqual([])
719
+ })
720
+
665
721
  test('definition filter', () => {
666
722
  const env = new MiniProgramEnv()
667
723
  const codeSpace = env.createCodeSpace('', true)