Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ModularLoad with Barba #119

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions assets/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import modular from 'modujs';
import * as modules from './modules';
import globals from './globals';
import { html } from './utils/environment';
import { $html } from './utils/dom';
import config from './config';

const app = new modular({
modules: modules
Expand All @@ -28,8 +29,8 @@ function init() {

app.init(app);

html.classList.add('is-loaded');
html.classList.add('is-ready');
html.classList.remove('is-loading');
$html.classList.add(config.CSS_CLASS.LOADED);
$html.classList.add(config.CSS_CLASS.READY);
$html.classList.remove(config.CSS_CLASS.LOADING);
}

15 changes: 15 additions & 0 deletions assets/scripts/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const env = process.env.NODE_ENV

export default config = Object.freeze({
// Environments
ENV: env,
IS_PROD: env === 'production',
IS_DEV: env === 'development',

// CSS class names
CSS_CLASS: {
LOADING: 'is-loading',
READY: 'is-ready',
LOADED: 'is-loaded',
},
})
27 changes: 16 additions & 11 deletions assets/scripts/modules/Load.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { module } from 'modujs';
import modularLoad from 'modularload';
import barba from '@barba/core';
import config from '../config'

export default class extends module {
constructor(m) {
super(m);
}

init() {
const load = new modularLoad({
enterDelay: 0,
transitions: {
customTransition: {}
}
});

load.on('loaded', (transition, oldContainer, newContainer) => {
this.call('destroy', oldContainer, 'app');
this.call('update', newContainer, 'app');
barba.init({
debug: config.IS_DEV,
schema: {
prefix: 'data-load',
},
transitions: [{
name: 'default-transition',
leave: (data) => {
this.call('destroy', data.current.container, 'app');
},
enter: (data) => {
this.call('update', data.next.container, 'app');
}
}]
});
}
}
4 changes: 4 additions & 0 deletions assets/scripts/utils/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const $html = document.documentElement;
const $body = document.body;

export { $html, $body };
8 changes: 0 additions & 8 deletions assets/scripts/utils/environment.js

This file was deleted.

3 changes: 1 addition & 2 deletions assets/scripts/utils/visibility.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isFunction } from './is';
import { arrayContains, findByKeyValue, removeFromArray } from './array';
import { $document, $window, $html, $body } from './environment';

const CALLBACKS = {
hidden: [],
Expand All @@ -22,7 +21,7 @@ const PREFIX = 'v-';
let UUID = 0;

// Main event
$document.on('visibilitychange', function(event) {
document.addEventListener('visibilitychange', function(event) {
if (document.hidden) {
onDocumentChange('hidden');
} else {
Expand Down
50 changes: 39 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"build": "node --experimental-json-modules --no-warnings build/build.js"
},
"dependencies": {
"@barba/core": "^2.9.7",
"locomotive-scroll": "^4.1.4",
"modujs": "^1.4.2",
"modularload": "^1.2.6",
"normalize.css": "^8.0.1",
"svg4everybody": "^2.1.9"
},
Expand Down
Loading