Skip to content

Commit

Permalink
chromium 45 compat
Browse files Browse the repository at this point in the history
rip out Proxy, as it can't be polyfilled to Chromium 45
babelify api.js
  • Loading branch information
bgschiller committed Mar 5, 2018
1 parent c7375a5 commit aa21430
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 65 deletions.
6 changes: 4 additions & 2 deletions build/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@

print "Loading floorspace.js API script from: #{src_path + '/api.js'}\n\n"
api_scripts = File.open(src_path + '/api.js') {|file| file.read}
lodash = File.open('./node_modules/lodash/lodash.js') {|file| file.read}
lodash = File.open('./node_modules/lodash/lodash.min.js') {|file| file.read}

# the newline after #{scripts} is important, removing it causes everything after #{scripts} to be interpreted as a comment
embeddable_html = base_html + "
<script> #{lodash} </script>
<script>
#{lodash}
</script>
<script>
window.startApp = function() {
#{scripts}
Expand Down
33 changes: 19 additions & 14 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
/* global _ */
/* eslint-disable */

window.api = {
config: null,
initAlreadyRun: false,
openFloorplan: (data, _options) => {
const options = _options || { noReloadGrid: false };
openFloorplan: function openFloorplan(data, _options) {
var options = _options || { noReloadGrid: false };
try {
window.application.$store.dispatch('importFloorplan', {
clientWidth: document.getElementById('svg-grid').clientWidth,
clientHeight: document.getElementById('svg-grid').clientHeight,
data: JSON.parse(data),
options,
options: options
});
} catch (err) {
console.error(err);
return false;
}
return true;
},
importLibrary: (data) => {
importLibrary: function importLibrary(data) {
try {
window.application.$store.dispatch('importLibrary', { data: JSON.parse(data) });
} catch (err) {
return false;
}
return true;
},
exportFloorplan: () => window.application.$store.getters['exportData'],
setConfig: (config) => {
if (this.initAlreadyRun) {
exportFloorplan: function exportFloorplan() {
return window.application.$store.getters['exportData'];
},
setConfig: function setConfig(config) {
if (window.api.initAlreadyRun) {
throw new Error('The application has already been started, configuration cannot be changed.');
}

if (config === undefined) {
config = {}; // eslint-disable-line
}
if (config.snapMode && !_.includes(['grid-strict', 'grid-verts-edges'], config.snapMod)) {
throw new Error(`unrecognized value for snapMode: ${config.snapMode}. expected 'grid-strict' or 'grid-verts-edges'`);
throw new Error('unrecognized value for snapMode: ' + config.snapMode + '. expected \'grid-strict\' or \'grid-verts-edges\'');
}
window.api.config = Object.assign({
window.api.config = _.assign({
showImportExport: true,
units: 'si',
unitsEditable: true,
Expand All @@ -50,11 +53,13 @@ window.api = {
longitude: -104.9863,
},
snapMode: 'grid-strict',
onChange: () => { window.versionNumber += 1; },
onChange: function onChange() {
window.versionNumber += 1;
},
}, config);
},
init: () => {
if (this.initAlreadyRun) {
init: function init() {
if (window.api.initAlreadyRun) {
throw new Error('This method can only be run once!');
}
window.versionNumber = 0;
Expand All @@ -74,6 +79,6 @@ window.api = {
window.application.$store.dispatch('project/setMapLongitude', { longitude: window.api.config.defaultLocation.longitude });

window.application.$store.dispatch('application/setCurrentSnapMode', { snapMode: window.api.config.snapMode });
this.initAlreadyRun = true;
window.api.initAlreadyRun = true;
},
};
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission from the respective party.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/* eslint-disable no-new */
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill';
import Vue from 'vue';
import store from './store/index';

Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/models/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';
import libconfig from './libconfig';
import factory, { defaults } from './factory';
import factory, { getDefaults } from './factory';
import idFactory, { genName } from './../../utilities/generateId';
import geometryFactory from '../geometry/factory';
import helpers from './helpers';
Expand Down Expand Up @@ -192,7 +192,7 @@ export default {
const { object: { id } } = payload;

const windowDefnDefaults = _.pick(
defaults.WindowDefinition,
getDefaults('WindowDefinition'),
['height', 'width', 'window_spacing', 'wwr']);
// blank out the keys that don't make sense for that type.
if (payload.window_definition_mode === 'Window to Wall Ratio') {
Expand Down
50 changes: 16 additions & 34 deletions src/store/modules/models/factory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash';
import 'proxy-polyfill/proxy.min';
import idFactory from './../../utilities/generateId';
import generateColor from './../../utilities/generateColor';
import generateTexture from './../../utilities/generateTexture';
Expand All @@ -21,21 +20,10 @@ const makeReadPropertyAttr = (attribute) => {
return readPropertyAttr;
};

const readPropertyAttrs = (attr) => {
const rawValues = _.mapValues(schema.definitions, makeReadPropertyAttr(attr));
// We don't want the defaults to ever change, and we want to make sure
// that different uses of defaults produce different objects.
return new Proxy(rawValues, {
get(target, key) {
return _.cloneDeep(target[key]);
},
set() {
throw new Error('Please do not change the defaults.');
},
});
};
const readPropertyAttrs = attr =>
_.mapValues(schema.definitions, makeReadPropertyAttr(attr));

export const ip_defaults = readPropertyAttrs('default');
const ip_defaults = readPropertyAttrs('default');
if (ip_defaults.Project.config.units !== 'ip') {
// We're assuming the defaults in the schema are all in ip units.
// if that is not the case, we need to swap around which of
Expand All @@ -44,35 +32,29 @@ if (ip_defaults.Project.config.units !== 'ip') {
throw new Error(
'Expected default units to be ip. Code changes are required to change the default units');
}
export const si_defaults = _.mapValues(
const si_defaults = _.mapValues(
ip_defaults,
(value, key) => getConverter(key, 'ip_units', 'si_units')(value));

export const defaults = new Proxy(
{ ip_defaults, si_defaults },
{
get(target, key) {
return _.cloneDeep(_.get(window, 'application.$store.state.project.config.units', 'ip') === 'ip' ?
export const getDefaults = key =>
_.cloneDeep(_.get(window, 'application.$store.state.project.config.units', 'ip') === 'ip' ?
ip_defaults[key] :
si_defaults[key]);
},
},
);

export const allowableTypes = readPropertyAttrs('type');

export default {
Story(name) {
return {
...defaults.Story,
...getDefaults('Story'),
id: idFactory.generate(),
name,
color: generateColor('story'),
};
},
Space(name) {
return {
...defaults.Space,
...getDefaults('Space'),
id: idFactory.generate(),
name,
color: generateColor('space'),
Expand All @@ -81,7 +63,7 @@ export default {
},
Shading(name) {
return {
...defaults.Shading,
...getDefaults('Shading'),
id: idFactory.generate(),
name,
color: appconfig.palette.shading,
Expand Down Expand Up @@ -112,31 +94,31 @@ export default {
},
ThermalZone(opts = {}) {
return {
...defaults.ThermalZone,
...getDefaults('ThermalZone'),
id: idFactory.generate(),
color: generateColor('thermal_zone'),
name: opts.name,
};
},
SpaceType(opts = {}) {
return {
...defaults.SpaceType,
...getDefaults('SpaceType'),
id: idFactory.generate(),
color: generateColor('space_type'),
name: opts.name,
};
},
ConstructionSet(opts = {}) {
return {
...defaults.ConstructionSet,
...getDefaults('ConstructionSet'),
id: idFactory.generate(),
name: opts.name,
color: generateColor('construction_set'),
};
},
WindowDefn(opts = {}) {
return {
...defaults.WindowDefinition,
...getDefaults('WindowDefinition'),
id: idFactory.generate(),
name: opts.name,
wwr: null,
Expand All @@ -146,22 +128,22 @@ export default {
},
DaylightingControlDefn(opts = {}) {
return {
...defaults.DaylightingControlDefinition,
...getDefaults('DaylightingControlDefinition'),
id: idFactory.generate(),
name: opts.name,
};
},
DoorDefinition(opts = {}) {
return {
...defaults.DoorDefinition,
...getDefaults('DoorDefinition'),
id: idFactory.generate(),
name: opts.name,
texture: generateTexture('door_definition'),
};
},
PitchedRoof(opts = {}) {
return {
...defaults.PitchedRoof,
...getDefaults('PitchedRoof'),
id: idFactory.generate(),
name: opts.name,
color: generateColor('pitched_roof'),
Expand Down
3 changes: 1 addition & 2 deletions src/store/modules/models/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ const helpers = {
let i = 1;
while (!name) {
name = prefix + i;
if (models.find(m => m.name === name)) { name = ''; }
if (models.find(m => { console.log(`querying ${m}.name: ${m.name}`); return m.name === name; })) { name = ''; }
i += 1;
}

return name;
},

Expand Down
8 changes: 4 additions & 4 deletions src/store/modules/models/libconfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import factory, { allowableTypes, defaults } from './factory';
import factory, { allowableTypes, getDefaults } from './factory';
import validators from './validators';
import * as converters from './converters';
import { textures } from '../application/appconfig';
Expand Down Expand Up @@ -820,10 +820,10 @@ Object.keys(map).forEach((k) => {

if (
_.has(map[k], 'definitionName') &&
_.has(defaults, map[k].definitionName) &&
_.has(defaults[map[k].definitionName], col.name)
getDefaults(map[k].definitionName) &&
_.has(getDefaults(map[k].definitionName), col.name)
) {
col.default = defaults[map[k].definitionName][col.name];
col.default = getDefaults(map[k].definitionName)[col.name];
}
});
});
Expand Down
12 changes: 6 additions & 6 deletions src/store/utilities/importFloorplan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';
import idFactory from './generateId';
import { defaults } from '../modules/models/factory';
import { getDefaults } from '../modules/models/factory';

function maybeUpdateProject(project) {
// backwards compatibility changes:
Expand Down Expand Up @@ -31,9 +31,9 @@ function withHandleProp(arr) {
function withWindowDefinitionDefaults(arr) {
if (!arr || !arr.length) return [];
return arr.map(obj => ({
...defaults.WindowDefinition,
...getDefaults('WindowDefinition'),
// backwards compatibility: we used to call window_definition_mode "window_definition_type"
window_definition_mode: obj.window_definition_type || defaults.WindowDefinition.window_definition_mode,
window_definition_mode: obj.window_definition_type || getDefaults('WindowDefinition').window_definition_mode,
...obj,
window_definition_type: undefined,
}));
Expand All @@ -42,14 +42,14 @@ function withWindowDefinitionDefaults(arr) {
function withStoryDefaults(stories) {
return stories.map((story) => {
const multiplier = story.multiplier >= 1 ?
story.multiplier : defaults.Story.multiplier;
story.multiplier : getDefaults('Story').multiplier;

return {
...defaults.Story,
...getDefaults('Story'),
...story,
spaces: story.spaces
.map(space => ({
...defaults.Space,
...getDefaults('Space'),
...space,
})),
shading: withHandleProp(story.shading),
Expand Down

0 comments on commit aa21430

Please sign in to comment.