[gnome-shell] params: Simplify code



commit 46874eed05b9bb9e1ad8a5eee469c1f6eacb323f
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Jul 2 05:24:29 2019 +0200

    params: Simplify code
    
    Standard javascript now has Object.assign() which is very similar to
    Params.parse(), except that the latter by default disallows "extra"
    parameters. We can still leverage the standard API by simply
    implementing the error check, and then call out to Object.assign()
    for the actual parameter merging.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/612

 js/misc/params.js | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/js/misc/params.js b/js/misc/params.js
index 04691ba6a..0e3af9532 100644
--- a/js/misc/params.js
+++ b/js/misc/params.js
@@ -14,22 +14,12 @@
 //
 // Return value: a new object, containing the merged parameters from
 // @params and @defaults
-function parse(params, defaults, allowExtras) {
-    let ret = {}, prop;
-
-    if (!params)
-        params = {};
-
-    for (prop in params) {
-        if (!(prop in defaults) && !allowExtras)
-            throw new Error('Unrecognized parameter "' + prop + '"');
-        ret[prop] = params[prop];
-    }
-
-    for (prop in defaults) {
-        if (!(prop in params))
-            ret[prop] = defaults[prop];
+function parse(params = {}, defaults, allowExtras) {
+    if (!allowExtras) {
+        for (let prop in params)
+            if (!(prop in defaults))
+                throw new Error(`Unrecognized parameter "${prop}"`);
     }
 
-    return ret;
-}
\ No newline at end of file
+    return Object.assign(defaults, params);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]