From c85bcf51bc0f835816af82b1cbc40da3caccd36a Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 26 Sep 2017 18:18:54 +0200 Subject: 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 --- app/assets/javascripts/es6_browserified/helpers/clone.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/assets/javascripts/es6_browserified/helpers/clone.js 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 -- cgit v1.2.3