Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Created September 16, 2015 07:55
Show Gist options
  • Save jonschlinkert/8ff65abffad6fe92b9ae to your computer and use it in GitHub Desktop.
Save jonschlinkert/8ff65abffad6fe92b9ae to your computer and use it in GitHub Desktop.
function App() {
this.views = {};
this.plugins = [];
}
App.prototype.use = function (fn) {
var plugin = fn(this);
if (typeof plugin === 'function') {
this.plugins.push(plugin.bind(this));
}
return this;
};
App.prototype.create = function (name) {
var views = this.views[name] = new Views();
var self = this;
this.plugins.forEach(function (fn) {
views.use(fn.bind(this));
});
return views;
};
function Views() {
this.items = {};
this.plugins = [];
}
Views.prototype.use = function (fn) {
var plugin = fn.call(this, this);
if (typeof plugin === 'function') {
this.plugins.push(plugin);
}
return this;
};
Views.prototype.addView = function (val) {
var item = this.items[val.path] = new View(val);
item.addView = this.addView.bind(this);
var self = this;
this.plugins.forEach(function (fn) {
item.use(fn.bind(this));
}.bind(this));
return item;
};
function View(view) {
view = view || {};
}
View.prototype.use = function (fn) {
fn(this);
return this;
};
View.prototype.set = function (key, value) {
this[key] = value;
return this;
};
var app = new App();
app.use(function plugin(app) {
console.log('app')
console.log(app)
return function (collection) {
console.log('collection')
return function (view) {
console.log('view')
}
}
})
.create('pages')
.addView({path: 'foo'})
.addView({path: 'bar'})
.addView({path: 'baz'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment