File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -604,7 +604,15 @@ class I18n extends EventEmitter {
604604 hasLoadedNamespace : clone . hasLoadedNamespace . bind ( clone )
605605 } ;
606606 if ( forkResourceStore ) {
607- clone . store = new ResourceStore ( this . store . data , mergedOptions ) ;
607+ // faster than const clonedData = JSON.parse(JSON.stringify(this.store.data))
608+ const clonedData = Object . keys ( this . store . data ) . reduce ( ( prev , l ) => {
609+ prev [ l ] = { ...this . store . data [ l ] } ;
610+ return Object . keys ( prev [ l ] ) . reduce ( ( acc , n ) => {
611+ acc [ n ] = { ...prev [ l ] [ n ] } ;
612+ return acc ;
613+ } , { } ) ;
614+ } , { } ) ;
615+ clone . store = new ResourceStore ( clonedData , mergedOptions ) ;
608616 clone . services . resourceStore = clone . store ;
609617 }
610618 clone . translator = new Translator ( clone . services , mergedOptions ) ;
Original file line number Diff line number Diff line change @@ -99,14 +99,16 @@ describe('i18next', () => {
9999 } ,
100100 } ) ;
101101 newInstance = orgInstance . cloneInstance ( { forkResourceStore : true , keySeparator : '__' } ) ;
102+ newInstance . addResourceBundle ( 'en' , 'translation' , {
103+ deeper : { key : 'value here cloned' } ,
104+ } ) ;
102105 } ) ;
103106
104107 it ( 'it not has shared instance of resource store' , ( ) => {
105108 expect ( newInstance . store ) . not . to . equal ( orgInstance . store ) ;
106109 expect ( orgInstance . t ( 'deeper.key' ) ) . to . equal ( 'value here' ) ;
107110 expect ( orgInstance . t ( 'deeper.key' ) ) . not . to . equal ( newInstance . t ( 'deeper.key' ) ) ;
108- expect ( newInstance . t ( 'deeper__key' ) ) . to . equal ( 'value here' ) ;
109- expect ( orgInstance . t ( 'deeper.key' ) ) . to . equal ( newInstance . t ( 'deeper__key' ) ) ;
111+ expect ( newInstance . t ( 'deeper__key' ) ) . to . equal ( 'value here cloned' ) ;
110112 } ) ;
111113 } ) ;
112114 } ) ;
You can’t perform that action at this time.
0 commit comments