From 9c5ac1232eca928a1125f6680a8186c83d4b94cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Izurieta?= Date: Wed, 26 Oct 2016 10:27:21 +0200 Subject: [PATCH 1/2] Extracted L to a module and created dummy implementation for fastboot --- addon/L.js | 21 +++++++++++++++++++ addon/components/base-layer.js | 2 +- addon/helpers/div-icon.js | 2 +- addon/helpers/icon.js | 2 +- addon/helpers/lat-lng-bounds.js | 2 +- addon/helpers/point.js | 2 +- app/initializers/leaflet-assets.js | 2 +- index.js | 6 +++++- tests/assertions/bounds-contain.js | 2 +- tests/helpers/locations.js | 3 ++- .../components/geojson-layer-test.js | 2 +- .../components/leaflet-map-test.js | 2 +- .../components/marker-collection-test.js | 2 +- .../components/marker-layer-test.js | 2 +- tests/integration/components/popup-test.js | 2 +- tests/integration/components/tooltip-test.js | 2 +- tests/unit/helpers/div-icon-test.js | 2 +- tests/unit/helpers/icon-test.js | 2 +- tests/unit/helpers/lat-lng-bounds-test.js | 2 +- tests/unit/helpers/point-test.js | 2 +- .../unit/initializers/leaflet-assets-test.js | 2 +- 21 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 addon/L.js diff --git a/addon/L.js b/addon/L.js new file mode 100644 index 00000000..6388c8ca --- /dev/null +++ b/addon/L.js @@ -0,0 +1,21 @@ +/* global L */ + +let L_ = null; + +if (typeof L !== 'undefined') { + L_ = L; +} else { + let N = () => {}; + + L_ = new Proxy({}, { + get() { + return N; + } + }); + + L_.Icon.Default = {}; + L_.tileLayer.wms = N; +} + +export default L_; + diff --git a/addon/components/base-layer.js b/addon/components/base-layer.js index 1929c358..a08317db 100644 --- a/addon/components/base-layer.js +++ b/addon/components/base-layer.js @@ -1,7 +1,7 @@ import Ember from 'ember'; import { ChildMixin } from 'ember-composability-tools'; import { InvokeActionMixin } from 'ember-invoke-action'; -/* global L */ +import L from 'ember-leaflet/L'; const { assert, computed, Component, run, K, A, String: { classify } } = Ember; diff --git a/addon/helpers/div-icon.js b/addon/helpers/div-icon.js index 02ceaf03..a1df2806 100644 --- a/addon/helpers/div-icon.js +++ b/addon/helpers/div-icon.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -/* global L */ +import L from 'ember-leaflet/L'; const { Helper: { helper } } = Ember; diff --git a/addon/helpers/icon.js b/addon/helpers/icon.js index eb871c8d..941c5fb8 100644 --- a/addon/helpers/icon.js +++ b/addon/helpers/icon.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -/* global L */ +import L from 'ember-leaflet/L'; const { Helper: { helper } } = Ember; diff --git a/addon/helpers/lat-lng-bounds.js b/addon/helpers/lat-lng-bounds.js index 4d8fe58d..bf13aaa7 100644 --- a/addon/helpers/lat-lng-bounds.js +++ b/addon/helpers/lat-lng-bounds.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -/* global L */ +import L from 'ember-leaflet/L'; const { Helper: { helper } } = Ember; diff --git a/addon/helpers/point.js b/addon/helpers/point.js index fcdf6b1f..8a6d6841 100644 --- a/addon/helpers/point.js +++ b/addon/helpers/point.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -/* global L */ +import L from 'ember-leaflet/L'; const { Helper: { helper } } = Ember; diff --git a/app/initializers/leaflet-assets.js b/app/initializers/leaflet-assets.js index f179d054..ada07f6c 100644 --- a/app/initializers/leaflet-assets.js +++ b/app/initializers/leaflet-assets.js @@ -1,5 +1,5 @@ import ENV from '../config/environment'; -/* global L */ +import L from 'ember-leaflet/L'; export function initialize(/* container, application */) { L.Icon.Default.imagePath = `${ENV.rootURL || ENV.baseURL || '/'}assets/images/`; diff --git a/index.js b/index.js index 541a14b1..aa5c42c6 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,10 @@ module.exports = { included: function(app) { this._super.included.apply(this, arguments); + if (process.env.EMBER_CLI_FASTBOOT) { + return; + } + // If the addon has the _findHost() method (in ember-cli >= 2.7.0), we'll just // use that. if (typeof this._findHost === 'function') { @@ -23,7 +27,7 @@ module.exports = { do { app = current.app || app; } while (current.parent.parent && (current = current.parent)); - + //import javascript app.import(app.bowerDirectory + '/leaflet/dist/leaflet-src.js'); diff --git a/tests/assertions/bounds-contain.js b/tests/assertions/bounds-contain.js index 60bfc8c1..5479ec0a 100644 --- a/tests/assertions/bounds-contain.js +++ b/tests/assertions/bounds-contain.js @@ -1,4 +1,4 @@ -/* global L */ +import L from 'ember-leaflet/L'; export default function boundsContain(bounds1, bounds2, msg = 'Bounds 1 doesn\'t contain bounds 2') { // use this.push to add the assertion. diff --git a/tests/helpers/locations.js b/tests/helpers/locations.js index 03e69385..80a8db6d 100644 --- a/tests/helpers/locations.js +++ b/tests/helpers/locations.js @@ -1,4 +1,5 @@ -/* global L */ +import L from 'ember-leaflet/L'; + export default { nyc: L.latLng(40.713282, -74.006978), sf: L.latLng(37.77493, -122.419415), diff --git a/tests/integration/components/geojson-layer-test.js b/tests/integration/components/geojson-layer-test.js index 754853a5..244ced1b 100644 --- a/tests/integration/components/geojson-layer-test.js +++ b/tests/integration/components/geojson-layer-test.js @@ -4,7 +4,7 @@ import { assertionInjector, assertionCleanup } from '../../assertions'; import GeoJSONLayerComponent from 'ember-leaflet/components/geojson-layer'; import locations from '../../helpers/locations'; import sampleGeoJSON from '../../helpers/sample-geojson'; -/* globals L */ +import L from 'ember-leaflet/L'; const emptyGeoJSON = { type: 'FeatureCollection', diff --git a/tests/integration/components/leaflet-map-test.js b/tests/integration/components/leaflet-map-test.js index 3bfc8edd..5b28df82 100644 --- a/tests/integration/components/leaflet-map-test.js +++ b/tests/integration/components/leaflet-map-test.js @@ -3,7 +3,7 @@ import hbs from 'htmlbars-inline-precompile'; import { assertionInjector, assertionCleanup } from '../../assertions'; import LeafletMapComponent from 'ember-leaflet/components/leaflet-map'; import locations from '../../helpers/locations'; -/* global L */ +import L from 'ember-leaflet/L'; let map; diff --git a/tests/integration/components/marker-collection-test.js b/tests/integration/components/marker-collection-test.js index 3e9a9ae6..b30e8919 100644 --- a/tests/integration/components/marker-collection-test.js +++ b/tests/integration/components/marker-collection-test.js @@ -5,7 +5,7 @@ import wait from 'ember-test-helpers/wait'; import { assertionInjector, assertionCleanup } from '../../assertions'; import MarkerLayerComponent from 'ember-leaflet/components/marker-layer'; import locations from '../../helpers/locations'; -/* globals L */ +import L from 'ember-leaflet/L'; const { run } = Ember; diff --git a/tests/integration/components/marker-layer-test.js b/tests/integration/components/marker-layer-test.js index 9ddb38e7..cd462f97 100644 --- a/tests/integration/components/marker-layer-test.js +++ b/tests/integration/components/marker-layer-test.js @@ -4,7 +4,7 @@ import { assertionInjector, assertionCleanup } from '../../assertions'; import hasEmberVersion from 'ember-test-helpers/has-ember-version'; import MarkerLayerComponent from 'ember-leaflet/components/marker-layer'; import locations from '../../helpers/locations'; -/* globals L */ +import L from 'ember-leaflet/L'; //Needed to silence leaflet autodetection error L.Icon.Default.imagePath = 'some-path'; diff --git a/tests/integration/components/popup-test.js b/tests/integration/components/popup-test.js index 5e6101ec..341aec0b 100644 --- a/tests/integration/components/popup-test.js +++ b/tests/integration/components/popup-test.js @@ -6,7 +6,7 @@ import wait from 'ember-test-helpers/wait'; import MarkerLayerComponent from 'ember-leaflet/components/marker-layer'; import ArrayPathLayerComponent from 'ember-leaflet/components/array-path-layer'; import locations from '../../helpers/locations'; -/* globals L */ +import L from 'ember-leaflet/L'; const { computed, run, A } = Ember; diff --git a/tests/integration/components/tooltip-test.js b/tests/integration/components/tooltip-test.js index 20f914b8..8cf70975 100644 --- a/tests/integration/components/tooltip-test.js +++ b/tests/integration/components/tooltip-test.js @@ -6,7 +6,7 @@ import wait from 'ember-test-helpers/wait'; import MarkerLayerComponent from 'ember-leaflet/components/marker-layer'; import ArrayPathLayerComponent from 'ember-leaflet/components/array-path-layer'; import locations from '../../helpers/locations'; -/* globals L */ +import L from 'ember-leaflet/L'; const { computed, run, A } = Ember; diff --git a/tests/unit/helpers/div-icon-test.js b/tests/unit/helpers/div-icon-test.js index c2cd42e5..0c8f9f39 100644 --- a/tests/unit/helpers/div-icon-test.js +++ b/tests/unit/helpers/div-icon-test.js @@ -1,6 +1,6 @@ import { divIcon } from 'dummy/helpers/div-icon'; import { module, test } from 'qunit'; -/* global L */ +import L from 'ember-leaflet/L'; module('Unit | Helper | div-icon'); diff --git a/tests/unit/helpers/icon-test.js b/tests/unit/helpers/icon-test.js index c50db829..f6ad5017 100644 --- a/tests/unit/helpers/icon-test.js +++ b/tests/unit/helpers/icon-test.js @@ -1,6 +1,6 @@ import { icon } from 'dummy/helpers/icon'; import { module, test } from 'qunit'; -/* global L */ +import L from 'ember-leaflet/L'; module('Unit | Helper | icon'); diff --git a/tests/unit/helpers/lat-lng-bounds-test.js b/tests/unit/helpers/lat-lng-bounds-test.js index 851a509b..35b96506 100644 --- a/tests/unit/helpers/lat-lng-bounds-test.js +++ b/tests/unit/helpers/lat-lng-bounds-test.js @@ -1,6 +1,6 @@ import { latLngBounds } from 'dummy/helpers/lat-lng-bounds'; import { module, test } from 'qunit'; -/* global L */ +import L from 'ember-leaflet/L'; module('Unit | Helper | lat-lng-bounds'); diff --git a/tests/unit/helpers/point-test.js b/tests/unit/helpers/point-test.js index 0985ed68..e3bdba6a 100644 --- a/tests/unit/helpers/point-test.js +++ b/tests/unit/helpers/point-test.js @@ -1,6 +1,6 @@ import { point } from 'dummy/helpers/point'; import { module, test } from 'qunit'; -/* global L */ +import L from 'ember-leaflet/L'; module('Unit | Helper | point'); diff --git a/tests/unit/initializers/leaflet-assets-test.js b/tests/unit/initializers/leaflet-assets-test.js index b22009ff..730c88c0 100644 --- a/tests/unit/initializers/leaflet-assets-test.js +++ b/tests/unit/initializers/leaflet-assets-test.js @@ -2,7 +2,7 @@ import Ember from 'ember'; import ENV from '../../../config/environment'; import { initialize } from '../../../initializers/leaflet-assets'; import { module, test } from 'qunit'; -/* global L */ +import L from 'ember-leaflet/L'; const { run, Application } = Ember; From b0ef2e6ac529a1913ebb781f62e783db6060acc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Izurieta?= Date: Mon, 14 Nov 2016 14:33:38 +0100 Subject: [PATCH 2/2] Support node.js < 6 when run with '--harmony_proxies' --- README.md | 4 ++++ addon/L.js | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3691b1c8..ad942fc2 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ Think of your map as a set of layers inside a container. Your main container wil * `ember test` * `ember test --server` +## Fastboot support + +There's rudimentary support for fastboot right now. Node.js 6.0 an up work out of the box. For node.js < 6.0 you have to start the fastboot server with `--harmony_proxies` like `node --harmony_proxies node_modules/.bin/ember fastboot`. + ## Building * `ember build` diff --git a/addon/L.js b/addon/L.js index 6388c8ca..7a4b7dfb 100644 --- a/addon/L.js +++ b/addon/L.js @@ -6,13 +6,13 @@ if (typeof L !== 'undefined') { L_ = L; } else { let N = () => {}; - - L_ = new Proxy({}, { + let handler = { get() { return N; } - }); + }; + L_ = Proxy.create ? Proxy.create(handler) : new Proxy({}, handler); L_.Icon.Default = {}; L_.tileLayer.wms = N; }