aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-09-26 18:18:54 +0200
committercedricnjanga2017-09-26 18:20:54 +0200
commitc85bcf51bc0f835816af82b1cbc40da3caccd36a (patch)
treeecd314724e701c78193cdea813dcc92424658115
parent9e8a839fcd5a910a40bc0b8cd3a5e7d3f9e7d0eb (diff)
downloadchouette-core-c85bcf51bc0f835816af82b1cbc40da3caccd36a.tar.bz2
Refs #4614
Add small helper to create a clone from the window variable the backend send to the JS part We then only deal with variable shared within the app and not with window variable than we delete if we specify it
-rw-r--r--app/assets/javascripts/es6_browserified/helpers/clone.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/app/assets/javascripts/es6_browserified/helpers/clone.js b/app/assets/javascripts/es6_browserified/helpers/clone.js
new file mode 100644
index 000000000..c3b627858
--- /dev/null
+++ b/app/assets/javascripts/es6_browserified/helpers/clone.js
@@ -0,0 +1,14 @@
+const _ = require("lodash")
+
+/* This function helps having a bit more security when we pass data from the backend to the React parts
+ It clones the obj (window variable) and then conditionnaly delete the window variable
+*/
+
+const clone = (window, key, deletable = false) => {
+ let obj = _.cloneDeep(window[key])
+
+ if (deletable) delete window[key]
+ return obj
+}
+
+module.exports = clone \ No newline at end of file