Commit 0537e825 authored by Christopher Davis's avatar Christopher Davis

Get rid of params.js

Object.assign does basically the same thing as Params.fill.
parent c31d0be6
......@@ -24,7 +24,6 @@ const Gtk = imports.gi.Gtk;
const Forecast = imports.app.forecast;
const WForecast = imports.app.weeklyForecast;
const Params = imports.misc.params;
const Util = imports.misc.util;
const SPINNER_SIZE = 128;
......@@ -42,9 +41,10 @@ var WeatherWidget = GObject.registerClass({
}, class WeatherWidget extends Gtk.Frame {
_init(params) {
params = Params.fill(params, { shadow_type: Gtk.ShadowType.NONE,
name: 'weather-page' });
super._init(params);
super._init(Object.assign({
shadow_type: Gtk.ShadowType.NONE,
name: 'weather-page'
}, params));
this._currentStyle = null;
this._info = null;
......
......@@ -21,7 +21,6 @@ const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Params = imports.misc.params;
const Util = imports.misc.util;
// In microseconds
......@@ -30,8 +29,9 @@ const ONE_HOUR = 3600*1000*1000;
var ForecastBox = GObject.registerClass(class ForecastBox extends Gtk.Frame {
_init(params) {
params = Params.fill(params, { shadow_type: Gtk.ShadowType.NONE });
super._init(params);
super._init(Object.assign({
shadow_type: Gtk.ShadowType.NONE
}, params));
this.get_accessible().accessible_name = _("Forecast");
this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
......
......@@ -21,17 +21,17 @@ const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Params = imports.misc.params;
const Util = imports.misc.util;
var WeeklyForecastFrame = GObject.registerClass(
class WeeklyForecastFrame extends Gtk.Frame {
_init(params) {
params = Params.fill(params, { shadow_type: Gtk.ShadowType.NONE,
name: 'weekly-forecast-frame',
width_request: 150 });
super._init(params);
super._init(Object.assign({
shadow_type: Gtk.ShadowType.NONE,
name: 'weekly-forecast-frame',
width_request: 150
}, params));
this.get_accessible().accessible_name = _("Weekly Forecast");
this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
......
......@@ -23,7 +23,6 @@ const GWeather = imports.gi.GWeather;
const City = imports.app.city;
const CurrentLocationController = imports.app.currentLocationController;
const Params = imports.misc.params;
const World = imports.shared.world;
const WorldView = imports.app.world;
const Util = imports.misc.util;
......
......@@ -23,7 +23,6 @@ const Gtk = imports.gi.Gtk;
const GWeather = imports.gi.GWeather;
const CurrentLocationController = imports.app.currentLocationController;
const Params = imports.misc.params;
const Util = imports.misc.util;
......@@ -31,8 +30,10 @@ var WorldContentView = GObject.registerClass(
class WorldContentView extends Gtk.Popover {
_init(application, window, params) {
params = Params.fill(params, { hexpand: false, vexpand: false });
super._init(params);
super._init(Object.assign({
hexpand: false,
vexpand: false
}, params));
this.get_accessible().accessible_name = _("World view");
......
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
// Params:
//
// A set of convenience functions for dealing with pseudo-keyword
// arguments.
//
// Examples:
//
// A function with complex arguments
// function myFunction(params) {
// params = Params.parse(params, { myFlags: Flags.NONE,
// anInt: 42,
// aString: 'hello, world!',
// });
// ... params.anInt, params.myFlags, params.aString ...
// }
// myFunction({ anInt: -1 });
//
// Extend a method to allow more params in a subclass
// The superclass can safely use Params.parse(), it won't see
// the extensions.
// const MyClass = class {
// ...
// method(params) {
// let mine = Params.filter(params, { anInt: 42 });
// this.parent(params);
// ... mine.anInt ...
// }
// });
// parse:
// @params: caller-provided parameter object, or %null
// @defaults: function-provided defaults object
//
// Examines @params and fills in default values from @defaults for
// any properties in @defaults that don't appear in @params.
// This function will throw a Error if @params contains a property
// that is not recognized. Use fill() or filter() if you don't
// want that.
//
// If @params is %null, this returns the values from @defaults.
//
// Return value: a new object, containing the merged parameters from
// @params and @defaults
function parse(params, defaults) {
let ret = {}, prop;
params = params || {};
for (prop in params) {
if (!(prop in defaults))
throw new Error('Unrecognized parameter "' + prop + '"');
ret[prop] = params[prop];
}
for (prop in defaults) {
if (!(prop in params))
ret[prop] = defaults[prop];
}
return ret;
}
// fill:
// @params: caller-provided parameter object, or %null
// @defaults: function-provided defaults object
//
// Examines @params and fills in default values from @defaults
// for any properties in @defaults that don't appear in @params.
//
// Differently from parse(), this function does not throw for
// unrecognized parameters.
//
// Return value: a new object, containing the merged parameters from
// @params and @defaults
function fill(params, defaults) {
let ret = {}, prop;
params = params || {};
for (prop in params)
ret[prop] = params[prop];
for (prop in defaults) {
if (!(prop in ret))
ret[prop] = defaults[prop];
}
return ret;
}
// filter:
// @params: caller-provided parameter object, or %null
// @defaults: function-provided defaults object
//
// Examines @params and returns an object containing the
// same properties as @defaults, but with values taken from
// @params where available.
// Then it removes from @params all matched properties.
//
// This is similar to parse(), but it accepts unknown properties
// and modifies @params for known ones.
//
// If @params is %null, this returns the values from @defaults.
//
// Return value: a new object, containing the merged parameters from
// @params and @defaults
function filter(params, defaults) {
let ret = {}, prop;
params = params || {};
for (prop in defaults) {
if (!(prop in params))
ret[prop] = defaults[prop];
}
for (prop in params) {
if (prop in defaults) {
ret[prop] = params[prop];
delete params[prop];
}
}
return ret;
}
......@@ -31,8 +31,6 @@ const Gtk = imports.gi.Gtk;
const System = imports.system;
const GWeather = imports.gi.GWeather;
const Params = imports.misc.params;
function loadUI(resourcePath, objects) {
let ui = new Gtk.Builder();
......
......@@ -3,7 +3,6 @@
<gresource prefix="/org/gnome/Weather/BackgroundService/js">
<file>service/main.js</file>
<file>service/searchProvider.js</file>
<file>misc/params.js</file>
<file>misc/util.js</file>
<file>shared/world.js</file>
</gresource>
......
......@@ -8,7 +8,6 @@
<file>app/main.js</file>
<file>app/window.js</file>
<file>app/world.js</file>
<file>misc/params.js</file>
<file>misc/util.js</file>
<file>shared/world.js</file>
</gresource>
......
......@@ -20,7 +20,6 @@ const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const GWeather = imports.gi.GWeather;
const Params = imports.misc.params;
const Util = imports.misc.util;
var WorldModel = GObject.registerClass({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment