UNPKG

janus

Version:

the two-faced application library-framework

105 lines (81 loc) 3.06 kB
// Generated by CoffeeScript 1.12.2 (function() { var App, Library, LibraryAttribute, Model, Resolver, attribute, attributes, isArray, isFunction, ref, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; Model = require('../model/model').Model; attribute = require('../model/schema').attribute; attributes = require('../model/attribute'); Library = require('./library').Library; Resolver = require('../model/resolver').Resolver; ref = require('../util/util'), isFunction = ref.isFunction, isArray = ref.isArray; LibraryAttribute = (function(superClass) { extend(LibraryAttribute, superClass); function LibraryAttribute() { return LibraryAttribute.__super__.constructor.apply(this, arguments); } LibraryAttribute.prototype.initial = function() { return new Library(); }; LibraryAttribute.prototype.writeInitial = true; return LibraryAttribute; })(attributes.Attribute); App = (function(superClass) { extend(App, superClass); function App() { return App.__super__.constructor.apply(this, arguments); } Object.defineProperty(App.prototype, 'views', { get: function() { return this.get_('views'); } }); Object.defineProperty(App.prototype, 'resolvers', { get: function() { return this.get_('resolvers'); } }); App.prototype.view = function(subject, criteria, options, parent) { var attr, attrs, i, klass, len, view; if (criteria == null) { criteria = {}; } if (options == null) { options = {}; } klass = this.get_('views').get(subject, criteria); if (klass == null) { return; } view = new klass(subject, Object.assign({ app: this, parent: parent }, options)); this.emit('createdView', view); if ((attrs = subject != null ? typeof subject.attributes === "function" ? subject.attributes() : void 0 : void 0)) { for (i = 0, len = attrs.length; i < len; i++) { attr = attrs[i]; if (attr.isReference === true && attr.autoResolve === true) { attr.resolveWith(this); } } } return view; }; App.prototype.resolve = function(request) { var result; result = (this._resolver$ != null ? this._resolver$ : this._resolver$ = this.resolver())(request); if (result != null) { this.emit('resolvedRequest', request, result); } return result; }; App.prototype.resolver = function() { return Resolver.fromLibrary(this.get_('resolvers')); }; return App; })(Model.build(attribute('views', LibraryAttribute), attribute('resolvers', LibraryAttribute))); module.exports = { App: App }; }).call(this);