Skip to content

Commit

Permalink
Merge pull request #46 from trafilea/feat/bootstrap-global-module
Browse files Browse the repository at this point in the history
feat(theme): add bootstrap global module
  • Loading branch information
sebastiandg7 authored Mar 30, 2021
2 parents aa25b9a + ac50ffa commit 49eb36b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ThemeContext, ThemeModule } from '<%= importPath %>/core';
import { ThemeGlobalModule } from '<%= importPath %>/global';
import documentReady from 'document-ready';

export interface ShopifyBootstrapOptions {
Expand Down Expand Up @@ -26,12 +27,12 @@ export function themeBootstrapFactory(
themeContext,
loadGlobal = true,
} = options;
const context = themeContext ?? {};
const context = themeContext ?? null;

documentReady(() => {
// Load globals
if (loadGlobal) {
// Global.load(context);
ThemeGlobalModule.load(context);
}

const importPromises: Array<Promise<any>> = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export interface ThemeContext {}
export interface ThemeContext {
themeName: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './theme-global-module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
ThemeModule,
ThemeContext,
ThemeOnReady,
} from '<%= importPath %>/core';

export class ThemeGlobalModule extends ThemeModule implements ThemeOnReady {
constructor(context: ThemeContext) {
super(context);
}

onReady() {
console.log('Theme Global Module: onReady() called');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@

<script>
window.addEventListener('DOMContentLoaded', function() {
window.themeBootstrap({
themeLayoutName: 'theme',
themeTemplateName: '{{ template }}',
themeContext: {},
loadGlobal: true,
window.themeBootstrap({
themeLayoutName: 'theme',
themeTemplateName: '{{ template }}',
themeContext: {% render 'theme-context' %},
loadGlobal: true,
});
});
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
themeName: '{{ theme.name }}',
}

0 comments on commit 49eb36b

Please sign in to comment.