Skip to content

Commit

Permalink
Merge pull request #302 from aminya/rollup
Browse files Browse the repository at this point in the history
Rollup - improve loading time
  • Loading branch information
suda authored Jul 10, 2020
2 parents 937f757 + b525422 commit 70d99ef
Show file tree
Hide file tree
Showing 17 changed files with 4,770 additions and 147 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto

# don't diff machine generated files
dist/ -diff
package-lock.json -diff
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- name: Install APM dependencies
run: |
apm ci # uses locked module. use `apm install` for non-locked
- name: Build
run: npm run build
- name: Run tests 👩🏾‍💻
run: npm run test

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
npm-debug.log
node_modules
dist
20 changes: 20 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let presets = [
["@babel/preset-env", {
targets: {
"electron": 5
}
}]
];

let plugins = ["@babel/plugin-proposal-optional-chaining"];

if (process.env.BABEL_ENV === "development") {
plugins.push("@babel/plugin-transform-modules-commonjs");
}

module.exports = {
presets: presets,
plugins: plugins,
exclude: "node_modules/**",
sourceMaps: "inline"
};
7 changes: 7 additions & 0 deletions iconsets/rollup-iconsets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is the entry file for iconsets rollup
import "./ionicons/ionicons.css";
import "./font-awesome/font-awesome.css";
import "./foundation/foundation-icons.css";
import "./icomoon/icomoon.css";
import "./devicon/devicon.css";
import "./mdi/materialdesignicons.css";
9 changes: 3 additions & 6 deletions lib/items/tool-bar-button-view.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {CompositeDisposable} = require('atom');
const { ToolBarItem } = require('./tool-bar-item');
import {CompositeDisposable} from 'atom';
import { ToolBarItem } from './tool-bar-item';

/**
* A button class with many options
Expand All @@ -12,9 +12,8 @@ const { ToolBarItem } = require('./tool-bar-item');
* @property {boolean} enabled
* @property {CompositeDisposable} subscriptions
*/
class ToolBarButtonView extends ToolBarItem {
export class ToolBarButtonView extends ToolBarItem {
/**
*
* @param {ButtonOptions} options
* @param {string} group
*/
Expand Down Expand Up @@ -238,5 +237,3 @@ function getTooltipPlacement () {
const toolbarPosition = atom.config.get('tool-bar.position');
return tooltipPlacement[toolbarPosition] || null;
}

module.exports.ToolBarButtonView = ToolBarButtonView;
4 changes: 1 addition & 3 deletions lib/items/tool-bar-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @property {number} priority
* @property {string} group
*/
class ToolBarItem {
export class ToolBarItem {
/**
* @param {ItemOptions} options
* @param {string} group
Expand All @@ -24,5 +24,3 @@ class ToolBarItem {
this.element = null;
}
}

module.exports.ToolBarItem = ToolBarItem;
6 changes: 2 additions & 4 deletions lib/items/tool-bar-spacer-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { ToolBarItem } = require('./tool-bar-item');
import { ToolBarItem } from './tool-bar-item';

class ToolBarSpacerView extends ToolBarItem {
export class ToolBarSpacerView extends ToolBarItem {
constructor (options, group) {
// first calling the super (ToolBarItem) constructor
super({
Expand All @@ -15,5 +15,3 @@ class ToolBarSpacerView extends ToolBarItem {
this.element.classList.add(...classNames);
}
}

module.exports.ToolBarSpacerView = ToolBarSpacerView;
4 changes: 2 additions & 2 deletions lib/raf-debounce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function rafDebounce (fn) {
export function rafDebounce (fn) {
let args, context, requestID;

function later () {
Expand All @@ -22,4 +22,4 @@ module.exports = function rafDebounce (fn) {
};

return debounced;
};
}
19 changes: 8 additions & 11 deletions lib/tool-bar-manager.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const { ToolBarItem } = require('./items/tool-bar-item');
const { ToolBarButtonView } = require('./items/tool-bar-button-view');
const { ToolBarSpacerView } = require('./items/tool-bar-spacer-view');
import { ToolBarItem } from './items/tool-bar-item';
import { ToolBarButtonView } from './items/tool-bar-button-view';
import { ToolBarSpacerView } from './items/tool-bar-spacer-view';

/**
*
* @property {string} group
* @property {ToolBarView} toolBarView
* @property {TouchBarManager} touchBarManager
*/
class ToolBarManager {
export class ToolBarManager {
/**
*
* @param {string} group
* @param {ToolBarView} toolBarView
* @param {TouchBarManager} touchBarManager
Expand All @@ -28,7 +27,7 @@ class ToolBarManager {
addItem (options) {
const item = new ToolBarItem(options, this.group);
this.toolBarView.addItem(item);
// this.touchBarManager.addItem(item); // TODO
// this.touchBarManager?.addItem(item); // TODO
return item;
}

Expand All @@ -39,7 +38,7 @@ class ToolBarManager {
addButton (options) {
const button = new ToolBarButtonView(options, this.group);
this.toolBarView.addItem(button);
this.touchBarManager.addButton(button);
this.touchBarManager?.addButton(button);
return button;
}

Expand All @@ -62,7 +61,7 @@ class ToolBarManager {
this.toolBarView.items
.filter(item => item.group === this.group)
.forEach(item => this.toolBarView.removeItem(item));
this.touchBarManager.removeGroup(this.group);
this.touchBarManager?.removeGroup(this.group);
}
}

Expand All @@ -73,6 +72,4 @@ class ToolBarManager {
onDidDestroy (callback) {
this.toolBarView.emitter.on('did-destroy', callback);
}
};

module.exports.ToolBarManager = ToolBarManager;
}
33 changes: 12 additions & 21 deletions lib/tool-bar-view.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const {CompositeDisposable, Emitter} = require('atom');
const rafDebounce = require('./raf-debounce');
import {CompositeDisposable, Emitter} from 'atom';
import {rafDebounce} from './raf-debounce';
import {useGutter} from './tool-bar.js'

const {useGutter} = require('./tool-bar.js')

module.exports = class ToolBarView {
export class ToolBarView {
constructor () {
this.element = document.createElement('div');
this.element.classList.add('tool-bar');
Expand All @@ -12,20 +11,12 @@ module.exports = class ToolBarView {
this.subscriptions = new CompositeDisposable();

this.subscriptions.add(
atom.commands.add('atom-workspace', 'tool-bar:toggle', () => {
this.toggle();
}),
atom.commands.add('atom-workspace', 'tool-bar:position-top', () => {
this.updatePosition('Top');
}),
atom.commands.add('atom-workspace', 'tool-bar:position-right', () => {
this.updatePosition('Right');
}),
atom.commands.add('atom-workspace', 'tool-bar:position-bottom', () => {
this.updatePosition('Bottom');
}),
atom.commands.add('atom-workspace', 'tool-bar:position-left', () => {
this.updatePosition('Left');
atom.commands.add("atom-workspace", {
'tool-bar:toggle': () => this.toggle(),
'tool-bar:position-top': () => this.updatePosition('Top'),
'tool-bar:position-right': () => this.updatePosition('Right'),
'tool-bar:position-bottom': () => this.updatePosition('Bottom'),
'tool-bar:position-left': () => this.updatePosition('Left'),
}),
atom.config.observe('tool-bar.iconSize', newValue => {
this.updateSize(newValue);
Expand Down Expand Up @@ -174,7 +165,7 @@ module.exports = class ToolBarView {

drawGutter () {
if (!useGutter) {return;}

this.element.classList.remove('gutter-top', 'gutter-bottom');

const visibleHeight = this.element.offsetHeight;
Expand Down Expand Up @@ -216,4 +207,4 @@ module.exports = class ToolBarView {
toggle () {
atom.config.set('tool-bar.visible', !atom.config.get('tool-bar.visible'));
}
};
}
33 changes: 19 additions & 14 deletions lib/tool-bar.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
const { ToolBarManager } = require('./tool-bar-manager');
const ToolBarView = require('./tool-bar-view');
const TouchBarManager = require('./touch-bar-manager');
import {ToolBarManager} from './tool-bar-manager';
import {ToolBarView} from './tool-bar-view';

let toolBarView = null;
let touchBarManager = null;

let useGutter = false;
exports.useGutter = useGutter;
export let useGutter = false;

exports.activate = function () {
export function activate() {
toolBarView = new ToolBarView();
touchBarManager = new TouchBarManager();
useGutter = atom.config.get('tool-bar.useGutter')
};
useTouchBar();
useGutter = atom.config.get('tool-bar.useGutter');
}

async function useTouchBar() {
if (atom.config.get('tool-bar.useTouchBar') && process.platform === 'darwin') {
let TouchBarManager = await import('./touch-bar-manager');
touchBarManager = new TouchBarManager();
}
}

exports.deactivate = function () {
export function deactivate() {
toolBarView.destroy();
toolBarView = null;
touchBarManager.destroy();
touchBarManager = null;
};
}

exports.provideToolBar = function provideToolBar () {
export function provideToolBar () {
return (group) => new ToolBarManager(group, toolBarView, touchBarManager);
};
}

exports.config = {
export const config = {
visible: {
type: 'boolean',
default: true,
Expand Down
16 changes: 5 additions & 11 deletions lib/touch-bar-manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const {TouchBar, nativeImage} = require('electron').remote;
import {remote} from 'electron';
const {TouchBar, nativeImage} = remote;
const {TouchBarButton} = TouchBar;

module.exports = class TouchBarManager {
export class TouchBarManager {
constructor () {
this.buttons = [];
}
Expand All @@ -12,7 +13,6 @@ module.exports = class TouchBarManager {
}

addButton (button) {
if (!this._useTouchBar()) return;
if (this.buttons.length >= 7) return;

this._renderButton(button).then(icon => {
Expand All @@ -32,8 +32,6 @@ module.exports = class TouchBarManager {
}

update () {
if (!this._useTouchBar()) return;

if (this._updateDebounce) clearTimeout(this._updateDebounce);
this._updateDebounce = setTimeout(() => this._setTouchBar(), 100);
}
Expand All @@ -42,11 +40,7 @@ module.exports = class TouchBarManager {
this.buttons = this.buttons.filter(button => button.group !== group);
this.update();
}

_useTouchBar () {
return process.platform === 'darwin' && atom.config.get('tool-bar.useTouchBar');
}


_renderButton (button) {
return document.fonts.ready.then(() => {
if (!(button.element instanceof HTMLElement)) return;
Expand Down Expand Up @@ -86,4 +80,4 @@ module.exports = class TouchBarManager {
atom.getCurrentWindow().setTouchBar(touchBar);
this._updateDebounce = null;
}
};
}
Loading

0 comments on commit 70d99ef

Please sign in to comment.