Skip to content

Commit

Permalink
Merge branch 'feature/core-11-bug-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
s3bba committed Feb 13, 2024
2 parents 3be004a + 6288174 commit a9a94fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/magnolia.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import {Router} from "./router";
import {empty_data_fn, ViewComposeFn, ViewData} from "./ui/view";

// This restricts the global scope to only have one instance of Magnolia
// Is this a good idea? I honestly don't know, but it's what I'm choosing go with for now
let instance: Magnolia;

/**
* Retrieves the instance of the Magnolia object.
* This function *can* return undefined if Magnolia#init() has not been called.
*
* @returns {Magnolia} The instance of the Magnolia object
*/
export function magnolia(): Magnolia {
return instance;
}

/**
* Represents the Magnolia application.
*/
Expand Down Expand Up @@ -37,11 +51,11 @@ export class Magnolia {
* @throws {Error} - If Magnolia#init() has already been called
*/
public init(): void {
if (magnolia !== undefined) {
if (instance !== undefined) {
throw new Error("Magnolia#init() was already called")
}

magnolia = this;
instance = this;

// Get the current path
const base: string = window.location.protocol + "//" + window.location.host;
Expand Down Expand Up @@ -75,7 +89,3 @@ export class Magnolia {
}

}

// This restricts the global scope to only have one instance of Magnolia
// Is this a good idea? I honestly don't know, but it's what I'm choosing go with for now
export let magnolia: Magnolia;
2 changes: 1 addition & 1 deletion src/ui/node_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class MgRouterAnchor extends MgAnchor {
super(url, text);
this.html_element.onclick = (event: MouseEvent) => {
event.preventDefault();
magnolia.router().navigate(url);
magnolia().router().navigate(url);
}
}
}
Expand Down

0 comments on commit a9a94fe

Please sign in to comment.