UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

141 lines (128 loc) 4.13 kB
// Generated by github.com/steida/coffee2closure 900.1.18 /** @fileoverview Presenter orchestrates model/collection loading and view showing. Every presenter is associated with some url. When url is matched, este.App will call presenter's load method and pass parsed url parameters. Load method has to return goog.result.Result to signalize that data are loaded. When data are loaded and user did't try to load another presenter during loading, show method is called. */ var 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.superClass_ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; goog.provide('este.app.Presenter'); goog.require('este.app.View'); goog.require('este.Base'); goog.require('goog.net.HttpStatus'); goog.require('goog.result'); /** @constructor @extends {este.Base} */ este.app.Presenter = function() { este.app.Presenter.superClass_.constructor.call(this); } extend(este.app.Presenter, superClass); /** Presenter's view. Should be created in constructor. @type {este.app.View} */ este.app.Presenter.prototype.view = null; /** Storage used for model persistence. By default defined on este.App, but we can override it for concrete presenter. @type {este.storage.Base} */ este.app.Presenter.prototype.storage = null; /** Screen is used for view showing/hidding. By default defined on este.App, but we can override it for concrete presenter. @type {este.app.screen.Base} */ este.app.Presenter.prototype.screen = null; /** This helper method allows us to generate URL for concrete presenter, so we don't have to hardcode URLs in code. All URLs should be defined only at one place. In app.start method. Example: this.createUrl app.products.list.Presenter, 'id': 123 @type {Function} */ este.app.Presenter.prototype.createUrl = null; /** Redirect to another presenter from code. Example: this.redirect app.products.list.Presenter, 'id': 123 @type {Function} */ este.app.Presenter.prototype.redirect = null; /** Async data load. Use this method in subclassed presenter to load data for view. This method should be overridden. @param {Object=} params @return {!goog.result.Result} */ este.app.Presenter.prototype.load = function(params) { return goog.result.successfulResult(null); }; /** Called on successful load. @param {boolean} isNavigation @param {goog.result.Result} result */ este.app.Presenter.prototype.beforeShow = function(isNavigation, result) { if (!this.view) { return; } this.view.createUrl = this.createUrl; this.view.redirect = this.redirect; this.show(result); return this.screen.show(this.view, isNavigation); }; /** Called when next presenter is going to be shown. */ este.app.Presenter.prototype.beforeHide = function() { if (!this.view) { return; } this.hide(); return this.screen.hide(this.view); }; /** You can use this method to pass data into view or start watching view model events. This method should be overridden. @param {goog.result.Result} result @protected */ este.app.Presenter.prototype.show = function(result) {}; /** You can use this method to stop watching view model events. This method should be overridden. @protected */ este.app.Presenter.prototype.hide = function() {}; /** @param {!goog.result.Result} result @param {Function} onSuccess @protected */ este.app.Presenter.prototype.onResult = function(result, onSuccess) { goog.result.waitOnSuccess(result, (function(_this) { return function() { return onSuccess.call(_this); }; })(this)); return goog.result.waitOnError(result, (function(_this) { return function(error) { return _this.dispatchEvent({ type: 'error', error: error }); }; })(this)); }; /** @override */ este.app.Presenter.prototype.disposeInternal = function() { this.view.dispose(); este.app.Presenter.superClass_.disposeInternal.call(this); };