From d012ba883b6e7f1f0c1d82d4b6788c0420dd187f Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Tue, 24 Sep 2019 15:27:44 +0200
Subject: [PATCH] Fix regression: cloned calculators do not lose their links
 anymore

---
 src/nub.ts                    | 2 +-
 src/pab/pab.ts                | 4 ++--
 src/param/param-definition.ts | 7 ++++---
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/nub.ts b/src/nub.ts
index ae103e29..afaa5e56 100644
--- a/src/nub.ts
+++ b/src/nub.ts
@@ -1056,7 +1056,7 @@ export abstract class Nub extends ComputeNode implements IObservable {
             // store old parameters state
             if (keepParametersState && hasOldChild) {
                 for (const p of this._children[index].parameterIterator) {
-                    parametersState[p.symbol] = p.objectRepresentation();
+                    parametersState[p.symbol] = p.objectRepresentation([]);
                 }
             }
 
diff --git a/src/pab/pab.ts b/src/pab/pab.ts
index ccb3b053..56af3ef9 100644
--- a/src/pab/pab.ts
+++ b/src/pab/pab.ts
@@ -229,9 +229,9 @@ export class Pab extends Nub {
      */
     public objectRepresentation(extra?: object) {
         // regular serialization
-        const ret: any = super.objectRepresentation(extra);
+        const ret: any = super.objectRepresentation(extra, []);
         // downwall
-        ret.downWall = this.downWall.objectRepresentation();
+        ret.downWall = this.downWall.objectRepresentation(undefined, []);
         return ret;
     }
 
diff --git a/src/param/param-definition.ts b/src/param/param-definition.ts
index 36c03d96..8b2eef80 100644
--- a/src/param/param-definition.ts
+++ b/src/param/param-definition.ts
@@ -742,8 +742,9 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
     /**
      * Returns an object representation of the Parameter's current state
      * @param nubUidsInSession UIDs of Nubs that will be saved in session along with this one;
-     *                         useful to determine if linked parameters must be kept as links
-     *                         or have their value copied (if target is not in UIDs list)
+     *        useful to determine if linked parameters must be kept as links or have their value
+     *        copied (if target is not in UIDs list); if undefined, wil consider all Nubs as
+     *        available (ie. will not break links)
      */
     public objectRepresentation(nubUidsInSession?: string[]): { symbol: string, mode: string } {
         // parameter representation
@@ -770,7 +771,7 @@ export class ParamDefinition implements INamedIterableValues, IObservable {
                 break;
 
             case ParamValueMode.LINK:
-                if (nubUidsInSession !== undefined && nubUidsInSession.includes(this._referencedValue.nub.uid)) {
+                if (nubUidsInSession === undefined || nubUidsInSession.includes(this._referencedValue.nub.uid)) {
                     // target Nub is available in session, link won't get broken
                     paramRep.targetNub = this._referencedValue.nub.uid;
                     paramRep.targetParam = this._referencedValue.symbol;
-- 
GitLab