Skip to content
This repository was archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #175 from gribnoysup/issue-174
Browse files Browse the repository at this point in the history
Move YMaps stuff from static props to constants
gribnoysup authored Jun 21, 2019
2 parents 9c0fc48 + 2ca35bc commit e4486b9
Showing 2 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
"microbundle": "microbundle --jsx React.createElement --name ReactYandexMaps --external react --globals react=React --define process.env.NODE_ENV=\"${NODE_ENV}\",__DOCZ__=false",
"microbundle:production": "NODE_ENV=production npm run microbundle -- --output ./dist/production",
"microbundle:development": "NODE_ENV=development npm run microbundle -- --output ./dist/development",
"microbundle:watch": "NODE_ENV=development npm run microbundle -- --output ./dist/development --compress false --watch",
"microbundle:watch": "NODE_ENV=development npm run microbundle -- --output ./dist/development --no-compress --watch",
"docs:dev": "docz dev",
"docs:build": "docz build",
"docs:deploy": "now",
48 changes: 24 additions & 24 deletions src/YMaps.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import set from './util/set';

const YMAPS_ONLOAD = '__yandex-maps-api-onload__';

const YMAPS_ONERROR = '__yandex-maps-api-onerror__';

function getBaseUrl(isEnterprise) {
return `https://${isEnterprise ? 'enterprise.' : ''}api-maps.yandex.ru`;
}

const YMAPS_DEFAULT_QUERY = {
lang: 'ru_RU',
load: '',
ns: '',
mode: process.env.NODE_ENV !== 'production' ? 'debug' : 'release',
};

const PROMISES = {};

export class YMaps {
constructor(options) {
const hash = Date.now().toString(32);

this.options = options;
this.namespace = options.query.ns || YMaps.defaultQuery.ns;
this.namespace = options.query.ns || YMAPS_DEFAULT_QUERY.ns;

this.onload = YMaps.onloadCallback + '$$' + hash;
this.onerror = YMaps.onerrorCallback + '$$' + hash;
this.onload = YMAPS_ONLOAD + '$$' + hash;
this.onerror = YMAPS_ONERROR + '$$' + hash;

this.api;
this.promise;
@@ -25,12 +42,12 @@ export class YMaps {
}

getPromise() {
return this.namespace ? YMaps.promiseMap[this.namespace] : this.promise;
return this.namespace ? PROMISES[this.namespace] : this.promise;
}

setPromise(promise) {
return this.namespace
? (YMaps.promiseMap[this.namespace] = this.promise = promise)
? (PROMISES[this.namespace] = this.promise = promise)
: (this.promise = promise);
}

@@ -43,15 +60,15 @@ export class YMaps {
onload: this.onload,
onerror: this.onerror,
},
YMaps.defaultQuery,
YMAPS_DEFAULT_QUERY,
this.options.query
);

const queryString = Object.keys(query)
.map(key => `${key}=${query[key]}`)
.join('&');

const baseUrl = YMaps.getBaseUrl(this.options.enterprise);
const baseUrl = getBaseUrl(this.options.enterprise);

const url = [baseUrl, this.options.version, '?' + queryString].join('/');

@@ -103,20 +120,3 @@ export class YMaps {
}

YMaps._name = '__react-yandex-maps__';

YMaps.onloadCallback = '__yandex-maps-api-onload__';

YMaps.onerrorCallback = '__yandex-maps-api-onerror__';

YMaps.getBaseUrl = function getBaseUrl(isEnterprise) {
return `https://${isEnterprise ? 'enterprise.' : ''}api-maps.yandex.ru`;
};

YMaps.defaultQuery = {
lang: 'ru_RU',
load: '',
ns: '',
mode: process.env.NODE_ENV !== 'production' ? 'debug' : 'release',
};

YMaps.promiseMap = {};

0 comments on commit e4486b9

Please sign in to comment.