From 269723493e07292761de0fcf9e4dda1aa73ac3f4 Mon Sep 17 00:00:00 2001 From: Egor Halimonenko Date: Sat, 3 Aug 2024 23:06:19 +0300 Subject: [PATCH 1/2] $mol_compare_deep: fix cyclic reference bug with warmed cache --- compare/deep/deep.test.tsx | 20 ++++++++++++++++++++ compare/deep/deep.ts | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compare/deep/deep.test.tsx b/compare/deep/deep.test.tsx index 8e30f50e63d..bee1ad6df46 100644 --- a/compare/deep/deep.test.tsx +++ b/compare/deep/deep.test.tsx @@ -75,6 +75,26 @@ namespace $ { } , + 'same POJOs with cyclic reference with cache warmup'() { + const obj1 = { test: 1, obj3: null as unknown as Object } + const obj1_copy = { test: 1, obj3: null as unknown as Object } + const obj2 = { test: 2, obj1 } + const obj2_copy = { test: 2, obj1: obj1_copy } + const obj3 = { test: 3, obj2 } + const obj3_copy = { test: 3, obj2: obj2_copy } + + obj1.obj3 = obj3 + obj1_copy.obj3 = obj3_copy + + // warmup cache + $mol_assert_not( $mol_compare_deep( obj1 , {} ) ) + $mol_assert_not( $mol_compare_deep( obj2 , {} ) ) + $mol_assert_not( $mol_compare_deep( obj3 , {} ) ) + + $mol_assert_ok( $mol_compare_deep( obj3 , obj3_copy ) ) + + } , + 'Date'() { $mol_assert_ok( $mol_compare_deep( new Date( 12345 ) , new Date( 12345 ) ) ) $mol_assert_not( $mol_compare_deep( new Date( 12345 ) , new Date( 12346 ) ) ) diff --git a/compare/deep/deep.ts b/compare/deep/deep.ts index 0d71ecdf8ac..81832ea777f 100644 --- a/compare/deep/deep.ts +++ b/compare/deep/deep.ts @@ -36,11 +36,13 @@ namespace $ { } else { - left_cache = new WeakMap< any , boolean >([[ right, true ]]) + left_cache = new WeakMap< any , boolean >() $mol_compare_deep_cache.set( left , left_cache ) } + left_cache.set(right, true); + let result!: boolean try { From 22da30adfaa6852b67220900b8372a3c8790432d Mon Sep 17 00:00:00 2001 From: Ivan Nesterov <111433564+thenesterov@users.noreply.github.com> Date: Sun, 11 Aug 2024 17:33:04 +0500 Subject: [PATCH 2/2] $mol_unit_money: rur -> rub --- unit/money/money.ts | 2 +- unit/unit.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unit/money/money.ts b/unit/money/money.ts index 0e0fc92a09b..34b10348a27 100644 --- a/unit/money/money.ts +++ b/unit/money/money.ts @@ -9,7 +9,7 @@ namespace $ { } } - export class $mol_unit_money_rur extends $mol_unit_money { + export class $mol_unit_money_rub extends $mol_unit_money { postfix() { return ' ₽' } diff --git a/unit/unit.test.ts b/unit/unit.test.ts index f724aa9bf8b..604f6fd81e3 100644 --- a/unit/unit.test.ts +++ b/unit/unit.test.ts @@ -18,7 +18,7 @@ namespace $ { var usd1 = new $mol_unit_money_usd( 2 ) var usd2 = new $mol_unit_money_usd( 3 ) - var rur = new $mol_unit_money_rur( 2 ) + var rur = new $mol_unit_money_rub( 2 ) $mol_assert_equal( $mol_unit.summ( usd1 , usd2 ).toString() , '$5' ) $mol_assert_equal( usd1.mult( 2 ).toString() , '$4' )