From a30b2f17957c891e130fd8d70a3e59370e058da9 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 16 Aug 2012 21:43:23 +0200 Subject: [PATCH] Move ol.Object.createFromObject to its proper home as a simplified API function --- src/api/api.js | 24 ++++++++++++++++++++++++ src/api/object_test.js | 19 +++++++++++++++++++ src/ol/base/object.js | 15 --------------- src/ol/base/object_test.js | 15 --------------- 4 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 src/api/object_test.js diff --git a/src/api/api.js b/src/api/api.js index d01d3c23bb..5aebd36da4 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -5,6 +5,7 @@ goog.require('goog.dom'); goog.require('ol.Coordinate'); goog.require('ol.Layer'); goog.require('ol.Map'); +goog.require('ol.Object'); goog.require('ol.Projection'); goog.require('ol.createMap'); goog.require('ol.layer.OpenStreetMap'); @@ -35,6 +36,12 @@ ol3.Layers; ol3.MapOptions; +/** + * @typedef {Object|ol.Object} + */ +ol3.Object; + + /** * @typedef {ol.Projection|string} */ @@ -125,6 +132,23 @@ ol3.map = function(opt_mapOptions) { goog.exportProperty(ol3, 'map', ol3.map); +/** + * @param {ol3.Object} object Object. + * @return {ol.Object} Object. + */ +ol3.object = function(object) { + if (object instanceof ol.Object) { + return object; + } else if (goog.isObject(object)) { + var values = /** @type {Object} */ object; + return new ol.Object(values); + } else { + return null; + } +}; +goog.exportProperty(ol3, 'object', ol3.object); + + /** * @param {ol3.Projection} projection Projection. * @return {ol.Projection} Projection. diff --git a/src/api/object_test.js b/src/api/object_test.js new file mode 100644 index 0000000000..8df738f8d5 --- /dev/null +++ b/src/api/object_test.js @@ -0,0 +1,19 @@ +goog.require('goog.testing.jsunit'); +goog.require('ol.Object'); +goog.require('ol3'); + + +function testObject1() { + var obj = {k: 1}; + obj = ol3.object(obj); + assertTrue(obj instanceof ol.Object); + assertEquals(1, obj.get('k')); +} + + +function testObject2() { + var obj1 = new ol.Object(); + var obj2 = ol3.object(obj1); + assertTrue(obj2 === obj1); +} + diff --git a/src/ol/base/object.js b/src/ol/base/object.js index 2d67333247..52674edb18 100644 --- a/src/ol/base/object.js +++ b/src/ol/base/object.js @@ -67,21 +67,6 @@ ol.Object.capitalize = function(str) { }; -/** - * @param {ol.Object|Object} arg Argument. - * @return {ol.Object} Object. - */ -ol.Object.create = function(arg) { - if (arg instanceof ol.Object) { - return arg; - } else { - var object = new ol.Object(); - object.setOptions(arg); - return object; - } -}; - - /** * @param {ol.Object} obj Object. * @return {Object.} Accessors. diff --git a/src/ol/base/object_test.js b/src/ol/base/object_test.js index e93185f08d..03412f462f 100644 --- a/src/ol/base/object_test.js +++ b/src/ol/base/object_test.js @@ -367,21 +367,6 @@ function testBindSelf() { } -function testCreateFromObject() { - var obj = {k: 1}; - obj = ol.Object.create(obj); - assertTrue(obj instanceof ol.Object); - assertEquals(1, obj.get('k')); -} - - -function testCreateFromObject() { - var obj1 = new ol.Object(); - var obj2 = ol.Object.create(obj1); - assertTrue(obj2 === obj1); -} - - function testCreateWithOptions() { var obj = new ol.Object({k: 1}); assertEquals(1, obj.get('k'));