Skip to content

Commit

Permalink
Some code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarkelov committed Feb 15, 2019
1 parent e05192f commit ac90f94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
18 changes: 8 additions & 10 deletions src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ export default class VKApi {
resolve(window.VK);
};

if (document.getElementById("vk-openapi")) {
return;
}

const script = document.createElement("script");
if (!document.getElementById("vk-openapi")) {
const script = document.createElement("script");

script.type = "text/javascript";
script.id = "vk-openapi";
script.src = baseUrl;
script.async = true;
script.type = "text/javascript";
script.id = "vk-openapi";
script.src = baseUrl;
script.async = true;

document.head.appendChild(script);
document.head.appendChild(script);
}
});

return this.promise;
Expand Down
9 changes: 3 additions & 6 deletions src/VK.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable no-underscore-dangle */
/* global window */
import React from "react";
import PropTypes from "prop-types";

import VKContext from "./VKContext";
import VKApi from "./API";

import { isDOMReady } from "./utils";

let VKInstance = null;

export default class VK extends React.Component {
Expand Down Expand Up @@ -33,11 +34,7 @@ export default class VK extends React.Component {

componentDidMount() {
const { onApiAvailable, apiId } = this.props;
if (
typeof window !== "undefined" &&
window.document &&
window.document.createElement
) {
if (isDOMReady()) {
this.VKinit().then(vk => {
onApiAvailable(vk);
if (apiId) {
Expand Down
6 changes: 6 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* global window */
/* eslint-disable import/prefer-default-export */
export const isDOMReady = () =>
typeof window !== "undefined" &&
window.document &&
window.document.createElement;

0 comments on commit ac90f94

Please sign in to comment.