Skip to content

Commit 61b4362

Browse files
committed
modeling app structure after todomvc es6
1 parent dc706d3 commit 61b4362

File tree

11 files changed

+194
-132
lines changed

11 files changed

+194
-132
lines changed

assets/js/app/controller.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default class Controller {
2+
/**
3+
* @param {!Store} store A Store instance
4+
* @param {!View} view A View instance
5+
*/
6+
constructor(store, view) {
7+
8+
this.store = store;
9+
this.view = view;
10+
11+
console.log(this)
12+
13+
}
14+
}

assets/js/app/dom.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

assets/js/app/dropbox.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

assets/js/app/helpers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Returns a function, that, as long as it continues to be invoked, will not
2+
// be triggered. The function will be called after it stops being called for
3+
// N milliseconds. If `immediate` is passed, trigger the function on the
4+
// leading edge, instead of the trailing.
5+
export function debounce(func, wait, immediate) {
6+
let timeout;
7+
return function() {
8+
let context = this, args = arguments;
9+
let later = function() {
10+
timeout = null;
11+
if (!immediate) func.apply(context, args);
12+
};
13+
let callNow = immediate && !timeout;
14+
clearTimeout(timeout);
15+
timeout = setTimeout(later, wait);
16+
if (callNow) func.apply(context, args);
17+
};
18+
}

assets/js/app/index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
// import dom from './dom';
2-
import dropbox from './dropbox';
3-
import debounce from './utilities/debounce';
1+
import Store from './store';
2+
import View from './view';
3+
import Controller from './controller';
44

5-
let app = {
5+
/**
6+
* App structure inspired by https://github.com/tastejs/todomvc/tree/gh-pages/examples/vanilla-es6
7+
* */
68

7-
loadInProgress: false,
8-
prefix:'',
9-
padding:0,
10-
path:'',
9+
let app = {
1110

1211
start: function () {
1312

1413
console.log('app started');
1514

16-
dropbox.init();
15+
let store = new Store('responsive-css-sprite-generator');
16+
let view = new View();
1717

18-
window.addEventListener('resize', debounce(() => {
19-
console.log('resize');
20-
}, 250));
18+
new Controller(store, view);
2119

2220
}
2321

assets/js/app/store.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default class Store {
2+
/**
3+
* @param {!string} name Database name
4+
* @param {function()} [callback] Called when the Store is ready
5+
*/
6+
constructor(name, callback) {
7+
8+
// TODO: Hook up local storage
9+
10+
this.id = 0;
11+
this.blocks = [];
12+
this.loaded = 0;
13+
this.loadInProgress = false;
14+
this.prefix = '';
15+
this.padding = 0;
16+
this.path = '';
17+
18+
if(callback){
19+
callback();
20+
}
21+
22+
}
23+
}

assets/js/app/utilities/debounce.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

assets/js/app/view.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let instance = null;
2+
3+
export default class View {
4+
5+
constructor() {
6+
7+
if(!instance) {
8+
instance = this;
9+
} else {
10+
return instance;
11+
}
12+
13+
this.fileInput = document.getElementById("fileElem");
14+
this.fileList = document.getElementById("fileList");
15+
this.listItems = document.createElement('ul');
16+
this.prefix = document.getElementById("prefix");
17+
this.padding = document.getElementById("padding");
18+
this.path = document.getElementById("path");
19+
this.canvas = document.getElementById("canvas");
20+
this.css = document.getElementById("css");
21+
this.dimensions = document.getElementById("dimensions");
22+
this.dropbox = document.getElementById("dropbox");
23+
this.fileList.appendChild(this.listItems);
24+
25+
}
26+
27+
}

0 commit comments

Comments
 (0)