|
| 1 | +/** |
| 2 | + * Page Class Template |
| 3 | + */ |
| 4 | + |
| 5 | +/* global app */ |
| 6 | +/* jshint esversion: 6 */ |
| 7 | + |
| 8 | +class Page { |
| 9 | + constructor() { |
| 10 | + this.counter = 0; |
| 11 | + } |
| 12 | + |
| 13 | + logFuncHash(func) { |
| 14 | + console.log('%cpage.' + func + ': ' + window.location.hash, 'color:navy;'); |
| 15 | + } |
| 16 | + |
| 17 | + // Called once when the view is loaded with data |
| 18 | + setupView() { |
| 19 | + // ** Add custom page logic here |
| 20 | + this.logFuncHash('setup'); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Controller function that is called once before the route |
| 25 | + * will be loaded. This is usefull for calling web services |
| 26 | + * before any rendering happens. For example, see usage on the |
| 27 | + * core [pages/jsonData.js] file. |
| 28 | + * |
| 29 | + * When using Vue this will be called from the Vue instance |
| 30 | + * [mounted()] function. |
| 31 | + */ |
| 32 | + onRouteLoad() { |
| 33 | + console.log('%cPage Loaded', 'font-weight:bold;'); |
| 34 | + this.counter++; |
| 35 | + this.logFuncHash('onRouteLoad'); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Define the Controller [onBeforeRender()] function. |
| 40 | + * This gets called each time the view is redrawn before |
| 41 | + * the the HTML is rendered. |
| 42 | + * |
| 43 | + * When using Vue this function will not be called so instead |
| 44 | + * use [onRouteLoad()] to handle early controller logic. |
| 45 | + */ |
| 46 | + onBeforeRender() { |
| 47 | + this.logFuncHash('onBeforeRender'); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Define the Controller [onRendered()] function. |
| 52 | + * This gets called each time the view is redrawn. |
| 53 | + */ |
| 54 | + onRendered() { |
| 55 | + this.logFuncHash('onRendered'); |
| 56 | + this.setupView(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Define the Controller [onRouteUnload()] function. |
| 61 | + * This event gets called only once per hash change when |
| 62 | + * the current route is unloaded. It can be used to call |
| 63 | + * [window.clearTimeout()] for page timers or cleanup |
| 64 | + * for other resources. |
| 65 | + * |
| 66 | + * When using Vue this will be called from the Vue instance |
| 67 | + * [beforeDestroy()] function. |
| 68 | + */ |
| 69 | + onRouteUnload() { |
| 70 | + this.logFuncHash('onRouteUnload'); |
| 71 | + console.log('%cPage Unloaded', 'font-weight:bold;'); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +/** |
| 76 | + * Add page to app |
| 77 | + * The name defined here can be used with [data-page] from HTML |
| 78 | + */ |
| 79 | +app.addPage('pageName', Page); |
0 commit comments