From 1f052e0dcb710af27d05720b4a651f4ac6ad78da Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Tue, 6 Apr 2021 17:46:21 +0200 Subject: [PATCH] Make syncUserSettings support dot-separated paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of only 2 hard-coded nesting levels, as it was before. This is done in preparation for splitting the "enabled" flag into separate ones for each popup type. This patch here doesn't change any behavior or internal representation of the states. Bug: T277639 Change-Id: Icad669d1c9675ad6de22f478e254debe5d1936d7 --- resources/dist/index.js | Bin 44366 -> 44393 bytes resources/dist/index.js.map.json | Bin 211523 -> 211387 bytes src/changeListeners/syncUserSettings.js | 22 +++++++++++----------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/dist/index.js b/resources/dist/index.js index 442392eb4464a2f8031c505760e3e5beaf106044..1aef6d19cefb6d620782a71dc9ef61adaf652488 100644 GIT binary patch delta 127 zcmX?ii|OSprVU#QWHqacQcFsU@)Sz+iVJcwOEi@9lr;5l<4H?WNKEIB^D_Z*%qg20Qs8MscLFKW-5@WXlq-f brk1Huw3(~0n4M8?azljyqu%Dt6|+qMXss(` delta 117 zcmaEPi|O1grVU#QLUr;qtBX=gN{jLoQlm>^)zm;_bY5(2T4`Q#NoIbYLTRc-s!oYc zo=&Dtk!E#SVv$0=ZE>mwSVYr0RZR`ZNd-x3D%#rStEm-fl zUi|m}obP<+yWjqL={Gk%|DQKLy?*rK2akTdxzVY}1#4W0cx}cS6e8@2TLVHwyAp4z zA+1ro2wDnP;?@XWtYIM{Ia-g=xuk2BcH^}uAMo>mD!qs#pQD|SPy<1Uhi447A5wb`rc36vQdw)T$QznwVGs>Qtk-Q z2GWMwloKF+w|}KLXUzm6S-`6m9|=QbE&OOoMfXEaq;$TE#UC6*NPg#uwTPWrFG~kM zBkhPaBb4K2*$WV+*aScF(y6ceq~-Q%k{0v83qdE`yce}9q1=9t4u5k0-ac_0Y^mN1 z0cM&}YYGpae%~j9)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=ha3Xr5#Dj910Ct%oxulWTfww_tf}CZDNyDao z{?48K91>q7++5(BG&)aI^~g2_ovu?Cx>22SaAdFWq1ofK5Uwq8Pz~No=r1A`$_q__ z*8{j}ni3>hzqM_ZVH!drr&h;I+k!F2_-Dg9+c4W{EZBn6DFSn<5coqzbP<gc$ht+-W9!0J3%DcDRK$<}E;oG5I{nNWA_typ+=cx~c9>>5!b#?5o zKh~etCn?%Vh|6`Z-J(-^42LYtfj>^-c5oEE5wMQd=@kN_MSa&T=ypH@OaW|J5;m%G zjkK4uZ`8+p>taLqai{etb_0*5u*~-vUtYe@M19MMy+BR4_>4*ymw6Ia!M?FPVHzoi z?GeA?X%P?hJ+sOe`rzQ~-?lB#+Yy}JV8?-P&@?9qqBMXg0f*e+(>}dPJ-fgfx^0-% ze+9LZ4XQ-)H?9YSk4wIJ!B?ene!6#T09E4RDPrvxPoPc2u&d|wE zrDzM#Ld@|SvRrQu&a(}ON>>WQIxVBVSWUP;^Qj-b@Tnh-`9ASmC#(}E&c5Iouj&7t z^p5}h(BMz$CW_haM6)`P&SbKU#zeI;(adK*?;D>yQLomnIytd(Wp(}RY2WzWvx70~ zM2(i+Iq}JlRzBLSXPd2hWunncH?#L_FZ { syncIfChanged( - prevState, state, 'eventLogging', 'previewCount', + prevState, state, 'eventLogging.previewCount', userSettings.setPreviewCount ); syncIfChanged( - prevState, state, 'preview', 'enabled', + prevState, state, 'preview.enabled', userSettings.setIsEnabled ); @@ -37,12 +37,13 @@ export default function syncUserSettings( userSettings ) { * property if the reducer and property exist * * @param {Object} state tree - * @param {string} reducer key to access on the state tree - * @param {string} prop key to access on the reducer key of the state tree + * @param {string} path dot-separated path in the state tree * @return {*} */ -function get( state, reducer, prop ) { - return state[ reducer ] && state[ reducer ][ prop ]; +function get( state, path ) { + return path.split( '.' ).reduce( function ( element, key ) { + return element && element[ key ]; + }, state ); } /** @@ -51,15 +52,14 @@ function get( state, reducer, prop ) { * * @param {Object} prevState * @param {Object} state - * @param {string} reducer key to access on the state tree - * @param {string} prop key to access on the reducer key of the state tree + * @param {string} path dot-separated path in the state tree * @param {Function} sync function to be called with the newest value if * changed * @return {void} */ -function syncIfChanged( prevState, state, reducer, prop, sync ) { - const current = get( state, reducer, prop ); - if ( prevState && ( get( prevState, reducer, prop ) !== current ) ) { +function syncIfChanged( prevState, state, path, sync ) { + const current = get( state, path ); + if ( prevState && ( get( prevState, path ) !== current ) ) { sync( current ); } }