1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20/** 21 * @fileOverview 22 * Page constructor & definition 23 */ 24 25import Differ from './api/Differ'; 26import { requireModule } from './register'; 27import { updateActions, callTasks } from './api/index'; 28import { Options } from '../app/index'; 29import Vm from '../model/index'; 30import Document from '../../vdom/Document'; 31 32/** 33 * Directive description to native. 34 */ 35export interface Task { 36 module: string; 37 method: string; 38 args: number[]; 39} 40 41/** 42 * Page constructor for framework. 43 * @param {string} id 44 * @param {Options} options 45 * @param {string} packageName 46 */ 47export default class Page { 48 private _packageName: string; 49 private _id: string; 50 private _options: Options; 51 private _vm: Vm; 52 private _customComponentMap: object; 53 private _commonModules: object; 54 private _doc: Document; 55 private _differ: Differ; 56 private _i18nService: object; 57 private _dpiService: object; 58 private _lastSignal: number; 59 private _destroyed: boolean; 60 private readonly _routerParams: any; 61 62 constructor(id: string, options: Options, packageName: string, data: object) { 63 this._packageName = packageName || 'notset'; 64 this._id = id; 65 this._options = options || null; 66 this._vm = null; 67 this._customComponentMap = {}; 68 this._commonModules = {}; 69 this._doc = new Document(id, this._options.bundleUrl); 70 this._differ = new Differ(id); 71 this._routerParams = data; 72 } 73 74 /** 75 * LastSignal of this Page. 76 * @type {number} 77 */ 78 get lastSignal() { 79 return this._lastSignal; 80 } 81 82 set lastSignal(newLastSignal: number) { 83 this._lastSignal = newLastSignal; 84 } 85 86 /** 87 * PackageName of this Page. 88 * @type {string} 89 */ 90 get packageName() { 91 return this._packageName; 92 } 93 94 /** 95 * Id of this Page. 96 * @type {string} 97 */ 98 get id() { 99 return this._id; 100 } 101 102 set id(id: string) { 103 this._id = id; 104 } 105 106 /** 107 * Options of this Page. 108 * @type {Options} 109 */ 110 get options() { 111 return this._options; 112 } 113 114 set options(options: Options) { 115 this._options = options; 116 } 117 118 /** 119 * Vm of this Page. 120 * @type {Vm} 121 */ 122 get vm() { 123 return this._vm; 124 } 125 126 set vm(vm: Vm) { 127 this._vm = vm; 128 } 129 130 /** 131 * CustomComponentMap of this Page. 132 * @type {Object} 133 */ 134 get customComponentMap() { 135 return this._customComponentMap; 136 } 137 138 set customComponentMap(customComponentMap: object) { 139 this._customComponentMap = customComponentMap; 140 } 141 142 /** 143 * CommonModules of this Page. 144 * @type {Object} 145 */ 146 get commonModules() { 147 return this._commonModules; 148 } 149 150 set commonModules(commonModules: object) { 151 this._commonModules = commonModules; 152 } 153 154 /** 155 * Doc of this Page. 156 * @type {Document} 157 */ 158 get doc() { 159 return this._doc; 160 } 161 162 set doc(doc: Document) { 163 this._doc = doc; 164 } 165 166 /** 167 * Differ of this Page. 168 * @type {Differ} 169 */ 170 get differ() { 171 return this._differ; 172 } 173 174 set differ(differ: Differ) { 175 this._differ = differ; 176 } 177 178 /** 179 * I18nService of this Page. 180 * @type {Object} 181 */ 182 get i18nService() { 183 return this._i18nService; 184 } 185 186 set i18nService(i18nService: object) { 187 this._i18nService = i18nService; 188 } 189 190 /** 191 * DpiService of this page. 192 * @type {Object} 193 */ 194 get dpiService() { 195 return this._dpiService; 196 } 197 198 set dpiService(dpiService: object) { 199 this._dpiService = dpiService; 200 } 201 202 /** 203 * Destroyed of this page. 204 * @type {boolean} 205 */ 206 get destroyed() { 207 return this._destroyed; 208 } 209 210 set destroyed(destroyed: boolean) { 211 this._destroyed = destroyed; 212 } 213 214 /** 215 * Obtain methods of a module. 216 * @param {string} name 217 * @return {*} 218 */ 219 public requireModule(name: string): any { 220 return requireModule(this, name); 221 } 222 223 /** 224 * Collect all virtual-DOM mutations together and send them to renderer. 225 * @return {*} 226 */ 227 public updateActions(): any { 228 return updateActions(this); 229 } 230 231 /** 232 * Call all tasks from a page to renderer (native). 233 * @param {Task[] | Task} tasks 234 * @return {*} 235 */ 236 public callTasks(tasks: Task[] | Task): any { 237 return callTasks(this, tasks); 238 } 239 240 /** 241 * get params from other page. 242 * @type {Object} 243 */ 244 get routerParams() { 245 return this._routerParams; 246 } 247} 248