@inseefr/lunatic 3.11.0 → 3.11.2
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/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +19 -12
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.d.ts +2 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js +11 -5
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js +68 -0
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.ts +23 -14
- package/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +83 -0
- package/src/use-lunatic/commons/variables/lunatic-variables-store.ts +24 -13
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +1 -1
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +19 -12
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.d.ts +2 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.js +12 -5
- package/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js +68 -0
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
|
@@ -680,6 +680,89 @@ describe('lunatic-variables-store', () => {
|
|
|
680
680
|
variables.commit();
|
|
681
681
|
expect(variables.get('PRENOM')).toEqual('John');
|
|
682
682
|
});
|
|
683
|
+
|
|
684
|
+
it('should clean pairwise in two directions with a queue', () => {
|
|
685
|
+
variables.set('LINKS', [
|
|
686
|
+
[null, '1', '3'],
|
|
687
|
+
['1', null, '3'],
|
|
688
|
+
['2', '2', null],
|
|
689
|
+
]);
|
|
690
|
+
variables.set('PRENOM', ['Dad', 'Mom', 'Unknow']);
|
|
691
|
+
cleaningBehaviour(
|
|
692
|
+
variables,
|
|
693
|
+
{
|
|
694
|
+
PRENOM: {
|
|
695
|
+
LINKS: [
|
|
696
|
+
{
|
|
697
|
+
expression: 'PRENOM <> ""',
|
|
698
|
+
shapeFrom: 'PRENOM',
|
|
699
|
+
isAggregatorUsed: false,
|
|
700
|
+
},
|
|
701
|
+
],
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
PRENOM: [],
|
|
706
|
+
LINKS: [],
|
|
707
|
+
}
|
|
708
|
+
);
|
|
709
|
+
|
|
710
|
+
// when
|
|
711
|
+
variables.set('PRENOM', '', { iteration: [1] });
|
|
712
|
+
variables.set('PRENOM', '', { iteration: [2] });
|
|
713
|
+
|
|
714
|
+
expect(variables.get('PRENOM')).toEqual(['Dad', '', '']);
|
|
715
|
+
variables.commit();
|
|
716
|
+
// then
|
|
717
|
+
expect(variables.get('LINKS')).toEqual([
|
|
718
|
+
[null, null, null],
|
|
719
|
+
[null, null, null],
|
|
720
|
+
[null, null, null],
|
|
721
|
+
]);
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
it('should clean pairwise in two directions with a queue with canceling', () => {
|
|
725
|
+
variables.set('LINKS', [
|
|
726
|
+
[null, '1', '3'],
|
|
727
|
+
['1', null, '3'],
|
|
728
|
+
['2', '2', null],
|
|
729
|
+
]);
|
|
730
|
+
variables.set('PRENOM', ['Dad', 'Mom', 'Unknow']);
|
|
731
|
+
cleaningBehaviour(
|
|
732
|
+
variables,
|
|
733
|
+
{
|
|
734
|
+
PRENOM: {
|
|
735
|
+
LINKS: [
|
|
736
|
+
{
|
|
737
|
+
expression: 'PRENOM <> ""',
|
|
738
|
+
shapeFrom: 'PRENOM',
|
|
739
|
+
isAggregatorUsed: false,
|
|
740
|
+
},
|
|
741
|
+
],
|
|
742
|
+
},
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
PRENOM: [],
|
|
746
|
+
LINKS: [],
|
|
747
|
+
}
|
|
748
|
+
);
|
|
749
|
+
|
|
750
|
+
// when
|
|
751
|
+
variables.set('PRENOM', '', { iteration: [1] });
|
|
752
|
+
variables.set('PRENOM', '', { iteration: [2] });
|
|
753
|
+
|
|
754
|
+
expect(variables.get('PRENOM')).toEqual(['Dad', '', '']);
|
|
755
|
+
|
|
756
|
+
variables.set('PRENOM', 'Not Unknow', { iteration: [2] });
|
|
757
|
+
expect(variables.get('PRENOM')).toEqual(['Dad', '', 'Not Unknow']);
|
|
758
|
+
variables.commit();
|
|
759
|
+
// then
|
|
760
|
+
expect(variables.get('LINKS')).toEqual([
|
|
761
|
+
[null, null, '3'],
|
|
762
|
+
[null, null, null],
|
|
763
|
+
['2', null, null],
|
|
764
|
+
]);
|
|
765
|
+
});
|
|
683
766
|
});
|
|
684
767
|
|
|
685
768
|
describe('missing', () => {
|
|
@@ -66,6 +66,13 @@ class Timekey {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
export function getChangedKey(
|
|
70
|
+
variableName: string,
|
|
71
|
+
iteration?: IterationLevel
|
|
72
|
+
) {
|
|
73
|
+
return `${variableName} | ${JSON.stringify(iteration)}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
export class LunaticVariablesStore {
|
|
70
77
|
private readonly dictionary = new Map<string, LunaticVariable>();
|
|
71
78
|
private readonly eventTarget = new EventTarget();
|
|
@@ -95,7 +102,7 @@ export class LunaticVariablesStore {
|
|
|
95
102
|
const { changeHandler, disableCleaning, autoCommit } = options;
|
|
96
103
|
|
|
97
104
|
const store = new LunaticVariablesStore();
|
|
98
|
-
if (globalThis.window
|
|
105
|
+
if (globalThis.window !== undefined) {
|
|
99
106
|
(globalThis.window as any).lunaticStore = store; // Allow access to the store from the console
|
|
100
107
|
}
|
|
101
108
|
if (!source.variables) {
|
|
@@ -183,23 +190,25 @@ export class LunaticVariablesStore {
|
|
|
183
190
|
public enqueueSet(
|
|
184
191
|
name: string,
|
|
185
192
|
value: unknown,
|
|
186
|
-
args: Pick<EventArgs['change'], 'iteration' | 'cause'> = {}
|
|
193
|
+
args: Pick<EventArgs['change'], 'iteration' | 'cause'> = {},
|
|
194
|
+
// usefull for pairwise, iteration is used but we need to change all variable even if we touch to only one iteration
|
|
195
|
+
forcedChangedKey?: string
|
|
187
196
|
) {
|
|
188
197
|
if (this.autoCommit) {
|
|
189
198
|
this.set(name, typeof value === 'function' ? value() : value, args);
|
|
190
199
|
return;
|
|
191
200
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
this.set(name, value, args);
|
|
201
|
+
|
|
202
|
+
const changeKey = forcedChangedKey ?? getChangedKey(name, args.iteration);
|
|
203
|
+
|
|
204
|
+
this.queue[args.cause ?? 'default'].set(changeKey, () => {
|
|
205
|
+
// A function can be enqueued, we need to evaluate it to retrieve the value to set
|
|
206
|
+
// This is used for the resizing & cleaning, where we want to resize the last version of the variable
|
|
207
|
+
if (typeof value === 'function') {
|
|
208
|
+
value = value();
|
|
201
209
|
}
|
|
202
|
-
|
|
210
|
+
this.set(name, value, args);
|
|
211
|
+
});
|
|
203
212
|
}
|
|
204
213
|
|
|
205
214
|
public unqueueSet(
|
|
@@ -209,7 +218,9 @@ export class LunaticVariablesStore {
|
|
|
209
218
|
if (this.autoCommit) {
|
|
210
219
|
return;
|
|
211
220
|
}
|
|
212
|
-
this.queue[args.cause ?? 'default'].delete(
|
|
221
|
+
this.queue[args.cause ?? 'default'].delete(
|
|
222
|
+
getChangedKey(name, args.iteration)
|
|
223
|
+
);
|
|
213
224
|
}
|
|
214
225
|
|
|
215
226
|
/**
|