11import { PatchBuilder } from '../../../json-crdt-patch' ;
2- import { Model , ModelChangeType } from '../Model' ;
2+ import { Model } from '../Model' ;
33
44describe ( 'DOM Level 0, .onchange event system' , ( ) => {
55 it ( 'should trigger the onchange event when a value is set' , ( ) => {
66 const model = Model . withLogicalClock ( ) ;
77 let cnt = 0 ;
8- model . onchange = ( ) => {
8+ model . onpatch = ( ) => {
99 cnt ++ ;
1010 } ;
1111 expect ( cnt ) . toBe ( 0 ) ;
@@ -26,7 +26,7 @@ describe('DOM Level 0, .onchange event system', () => {
2626 it ( 'should trigger the onchange event when a value is set to the same value' , ( ) => {
2727 const model = Model . withLogicalClock ( ) ;
2828 let cnt = 0 ;
29- model . onchange = ( ) => {
29+ model . onpatch = ( ) => {
3030 cnt ++ ;
3131 } ;
3232 expect ( cnt ) . toBe ( 0 ) ;
@@ -42,7 +42,7 @@ describe('DOM Level 0, .onchange event system', () => {
4242 it ( 'should trigger the onchange event when a value is deleted' , ( ) => {
4343 const model = Model . withLogicalClock ( ) ;
4444 let cnt = 0 ;
45- model . onchange = ( ) => {
45+ model . onpatch = ( ) => {
4646 cnt ++ ;
4747 } ;
4848 expect ( cnt ) . toBe ( 0 ) ;
@@ -60,7 +60,7 @@ describe('DOM Level 0, .onchange event system', () => {
6060 it ( 'should trigger the onchange event when a non-existent value is deleted' , ( ) => {
6161 const model = Model . withLogicalClock ( ) ;
6262 let cnt = 0 ;
63- model . onchange = ( ) => {
63+ model . onpatch = ( ) => {
6464 cnt ++ ;
6565 } ;
6666 expect ( cnt ) . toBe ( 0 ) ;
@@ -78,7 +78,7 @@ describe('DOM Level 0, .onchange event system', () => {
7878 it ( 'should trigger when root value is changed' , ( ) => {
7979 const model = Model . withLogicalClock ( ) ;
8080 let cnt = 0 ;
81- model . onchange = ( ) => {
81+ model . onpatch = ( ) => {
8282 cnt ++ ;
8383 } ;
8484 expect ( cnt ) . toBe ( 0 ) ;
@@ -96,29 +96,12 @@ describe('DOM Level 0, .onchange event system', () => {
9696 } ) ;
9797
9898 describe ( 'event types' , ( ) => {
99- it ( 'should trigger the onchange event with a REMOTE event type' , ( ) => {
100- const model = Model . withLogicalClock ( ) ;
101- let cnt = 0 ;
102- model . onchange = ( type ) => {
103- expect ( type ) . toBe ( ModelChangeType . REMOTE ) ;
104- cnt ++ ;
105- } ;
106- const builder = new PatchBuilder ( model . clock . clone ( ) ) ;
107- builder . root ( builder . json ( { foo : 123 } ) ) ;
108- const patch = builder . flush ( ) ;
109- expect ( cnt ) . toBe ( 0 ) ;
110- model . applyPatch ( patch ) ;
111- expect ( cnt ) . toBe ( 1 ) ;
112- expect ( model . view ( ) ) . toStrictEqual ( { foo : 123 } ) ;
113- } ) ;
114-
11599 it ( 'should trigger the onchange event with a RESET event type' , ( ) => {
116100 const model1 = Model . withLogicalClock ( ) ;
117101 const model2 = Model . withLogicalClock ( ) ;
118102 model2 . api . root ( [ 1 , 2 , 3 ] ) ;
119103 let cnt = 0 ;
120- model1 . onchange = ( type ) => {
121- expect ( type ) . toBe ( ModelChangeType . RESET ) ;
104+ model1 . onreset = ( ) => {
122105 cnt ++ ;
123106 } ;
124107 expect ( cnt ) . toBe ( 0 ) ;
0 commit comments