Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Initialize with a PlainFactory instance by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Fletcher91 committed Nov 27, 2019
1 parent d520eac commit 72c2e4a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import {
} from "./types";

let setup: (factory?: DataFactory, override?: boolean) => void;
let globalFactory: DataFactory & any;
let globalFactory: DataFactory & any = DefaultFactory;
let globalSymbol: any;

function shouldOverride(rdfFactory: any, override: boolean) {
const factory = (globalThis as any)[rdfFactory];

return typeof factory === "undefined" || factory === DefaultFactory || override
}

if (typeof Symbol !== "undefined") {
const rdfFactory: unique symbol = Symbol.for('rdfFactory');

setup = function setup(factory = DefaultFactory, override = true) {
if (typeof (globalThis as any)[rdfFactory] === "undefined" || override) {
if (shouldOverride(rdfFactory, override)) {
(globalThis as any)[rdfFactory] = factory;
globalFactory = factory;
} else if (typeof globalFactory === "undefined" || override) {
Expand All @@ -29,7 +35,7 @@ if (typeof Symbol !== "undefined") {
const rdfFactory = 'rdfFactory';

setup = function setup(factory = DefaultFactory, override = true) {
if (typeof (globalThis as any)[rdfFactory] === "undefined" || override) {
if (shouldOverride(rdfFactory, override)) {
(globalThis as any)[rdfFactory] = factory;
globalFactory = factory;
} else if (typeof globalFactory === "undefined" || override) {
Expand Down

0 comments on commit 72c2e4a

Please sign in to comment.