maishu-chitu
Advanced tools
Comparing version 2.9.26 to 2.10.0
/*! | ||
* | ||
* maishu-chitu v2.9.26 | ||
* maishu-chitu v2.10.0 | ||
* https://github.com/ansiboy/chitu | ||
@@ -135,4 +135,3 @@ * | ||
function _parseUrl(app, url) { | ||
if (!app) throw Errors_1.Errors.argumentNull('app'); | ||
function _parseUrl(url) { | ||
if (!url) throw Errors_1.Errors.argumentNull('url'); | ||
@@ -173,2 +172,4 @@ var sharpIndex = url.indexOf('#'); | ||
exports.parseUrl = _parseUrl; | ||
function pareeUrlQuery(query) { | ||
@@ -234,3 +235,3 @@ var match, | ||
var routeData = _parseUrl(this, url); | ||
var routeData = _parseUrl(url); | ||
@@ -264,3 +265,3 @@ return routeData; | ||
_this2.showPageByUrl(url, true); | ||
_this2.showPageByUrl(url); | ||
}; | ||
@@ -276,10 +277,4 @@ | ||
key: "showPageByUrl", | ||
value: function showPageByUrl(url, fromCache) { | ||
value: function showPageByUrl(url) { | ||
if (!url) throw Errors_1.Errors.argumentNull('url'); | ||
var routeData = this.parseUrl(url); | ||
if (routeData == null) { | ||
throw Errors_1.Errors.noneRouteMatched(url); | ||
} | ||
var tempPageData = this.fetchTemplatePageData(); | ||
@@ -300,10 +295,4 @@ var result = null; | ||
if (result == null || result.name != routeData.pageName) { | ||
var args = routeData.values || {}; | ||
if (tempPageData) { | ||
args = Object.assign(args, tempPageData); | ||
} | ||
result = this.showPage(routeData.pageName, args); | ||
if (result == null || result.url != url) { | ||
result = this.showPage(url); | ||
} | ||
@@ -622,3 +611,3 @@ | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Errors */ "./out-es5/Errors.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Errors_1) { | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Errors */ "./out-es5/Errors.js"), __webpack_require__(/*! ./Application */ "./out-es5/Application.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Errors_1, Application_1) { | ||
"use strict"; | ||
@@ -646,4 +635,6 @@ | ||
this._displayer = params.displayer; | ||
this.data = params.data; | ||
this._name = params.name; | ||
var routeData = Application_1.parseUrl(params.url); | ||
this.data = Object.assign(routeData.values, params.data || {}); | ||
this._name = routeData.pageName; | ||
this._url = params.url; | ||
} | ||
@@ -740,2 +731,7 @@ | ||
}, { | ||
key: "url", | ||
get: function get() { | ||
return this._url; | ||
} | ||
}, { | ||
key: "app", | ||
@@ -839,3 +835,3 @@ get: function get() { | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Page */ "./out-es5/Page.js"), __webpack_require__(/*! ./Errors */ "./out-es5/Errors.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Page_1, Errors_1) { | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Page */ "./out-es5/Page.js"), __webpack_require__(/*! ./Application */ "./out-es5/Application.js"), __webpack_require__(/*! ./Errors */ "./out-es5/Errors.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Page_1, Application_1, Errors_1) { | ||
"use strict"; | ||
@@ -861,2 +857,3 @@ | ||
this.nodes = {}; | ||
this.MAX_PAGE_COUNT = 100; | ||
this.error = maishu_chitu_service_1.Callbacks(); | ||
@@ -970,7 +967,6 @@ this.parser = parser || this.defaultPageNodeParser(); | ||
key: "getPage", | ||
value: function getPage(node, values) { | ||
console.assert(node != null); | ||
value: function getPage(pageUrl, values) { | ||
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
var pageName = node.name; | ||
var cachePage = this.cachePages[pageName]; | ||
var cachePage = this.cachePages[pageUrl]; | ||
@@ -985,4 +981,4 @@ if (cachePage != null) { | ||
var page = this.createPage(pageName, values); | ||
this.cachePages[pageName] = page; | ||
var page = this.createPage(pageUrl, values); | ||
this.cachePages[pageUrl] = page; | ||
this.on_pageCreated(page); | ||
@@ -996,8 +992,8 @@ return { | ||
key: "createPage", | ||
value: function createPage(pageName, values) { | ||
value: function createPage(pageUrl, values) { | ||
var _this3 = this; | ||
if (!pageName) throw Errors_1.Errors.argumentNull('pageName'); | ||
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
var element = this.createPageElement(pageName); | ||
var element = this.createPageElement(pageUrl); | ||
var displayer = new this.pageDisplayType(this); | ||
@@ -1007,3 +1003,3 @@ console.assert(this.pageType != null); | ||
app: this, | ||
name: pageName, | ||
url: pageUrl, | ||
data: values, | ||
@@ -1039,11 +1035,9 @@ displayer: displayer, | ||
key: "showPage", | ||
value: function showPage(pageName, args, forceRender) { | ||
value: function showPage(pageUrl, args, forceRender) { | ||
args = args || {}; | ||
forceRender = forceRender == null ? false : true; | ||
if (!pageName) throw Errors_1.Errors.argumentNull('pageName'); | ||
var node = this.findSiteMapNode(pageName); | ||
if (node == null) throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
if (this.currentPage != null && this.currentPage.name == pageName) return this.currentPage; | ||
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageName'); | ||
if (this.currentPage != null && this.currentPage.url == pageUrl) return this.currentPage; | ||
var _this$getPage = this.getPage(node, args), | ||
var _this$getPage = this.getPage(pageUrl, args), | ||
page = _this$getPage.page, | ||
@@ -1053,6 +1047,4 @@ isNew = _this$getPage.isNew; | ||
if (isNew || forceRender) { | ||
var siteMapNode = this.findSiteMapNode(pageName); | ||
if (siteMapNode == null) throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
var action = siteMapNode.action; | ||
if (action == null) throw Errors_1.Errors.actionCanntNull(pageName); | ||
var action = this.findPageAction(pageUrl); | ||
if (action == null) throw Errors_1.Errors.actionCanntNull(pageUrl); | ||
action(page, this); | ||
@@ -1071,3 +1063,3 @@ } | ||
page.close(); | ||
delete this.cachePages[page.name]; | ||
delete this.cachePages[page.url]; | ||
this.page_stack = this.page_stack.filter(function (o) { | ||
@@ -1081,4 +1073,21 @@ return o != page; | ||
this.page_stack.push(page); | ||
if (this.page_stack.length > this.MAX_PAGE_COUNT) { | ||
var _page = this.page_stack.shift(); | ||
if (_page) this.closePage(_page); | ||
} | ||
} | ||
}, { | ||
key: "findPageAction", | ||
value: function findPageAction(pageUrl) { | ||
var routeData = Application_1.parseUrl(pageUrl); | ||
var pageName = routeData.pageName; | ||
var node = this.findSiteMapNode(pageName); | ||
if (node == null) throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
var action = node.action; | ||
if (action == null) throw Errors_1.Errors.actionCanntNull(pageName); | ||
return node.action; | ||
} | ||
}, { | ||
key: "findSiteMapNode", | ||
@@ -1085,0 +1094,0 @@ value: function findSiteMapNode(pageName) { |
/*! | ||
* | ||
* maishu-chitu v2.9.26 | ||
* maishu-chitu v2.10.0 | ||
* https://github.com/ansiboy/chitu | ||
@@ -110,5 +110,3 @@ * | ||
const DefaultPageName = "index"; | ||
function parseUrl(app, url) { | ||
if (!app) | ||
throw Errors_1.Errors.argumentNull('app'); | ||
function parseUrl(url) { | ||
if (!url) | ||
@@ -146,2 +144,3 @@ throw Errors_1.Errors.argumentNull('url'); | ||
} | ||
exports.parseUrl = parseUrl; | ||
function pareeUrlQuery(query) { | ||
@@ -180,3 +179,3 @@ let match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g, decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }; | ||
throw Errors_1.Errors.argumentNull('url'); | ||
let routeData = parseUrl(this, url); | ||
let routeData = parseUrl(url); | ||
return routeData; | ||
@@ -200,3 +199,3 @@ } | ||
} | ||
this.showPageByUrl(url, true); | ||
this.showPageByUrl(url); | ||
}; | ||
@@ -209,9 +208,5 @@ showPage(); | ||
} | ||
showPageByUrl(url, fromCache) { | ||
showPageByUrl(url) { | ||
if (!url) | ||
throw Errors_1.Errors.argumentNull('url'); | ||
var routeData = this.parseUrl(url); | ||
if (routeData == null) { | ||
throw Errors_1.Errors.noneRouteMatched(url); | ||
} | ||
let tempPageData = this.fetchTemplatePageData(); | ||
@@ -235,8 +230,4 @@ let result = null; | ||
} | ||
if (result == null || result.name != routeData.pageName) { | ||
let args = routeData.values || {}; | ||
if (tempPageData) { | ||
args = Object.assign(args, tempPageData); | ||
} | ||
result = this.showPage(routeData.pageName, args); | ||
if (result == null || result.url != url) { | ||
result = this.showPage(url); | ||
} | ||
@@ -446,3 +437,3 @@ return result; | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Errors */ "./out/Errors.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Errors_1) { | ||
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Errors */ "./out/Errors.js"), __webpack_require__(/*! ./Application */ "./out/Application.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Errors_1, Application_1) { | ||
"use strict"; | ||
@@ -462,4 +453,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this._displayer = params.displayer; | ||
this.data = params.data; | ||
this._name = params.name; | ||
let routeData = Application_1.parseUrl(params.url); | ||
this.data = Object.assign(routeData.values, params.data || {}); | ||
this._name = routeData.pageName; | ||
this._url = params.url; | ||
} | ||
@@ -523,2 +516,5 @@ on_showing() { | ||
} | ||
get url() { | ||
return this._url; | ||
} | ||
get app() { | ||
@@ -568,3 +564,3 @@ return this._app; | ||
}; | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Page */ "./out/Page.js"), __webpack_require__(/*! ./Errors */ "./out/Errors.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Page_1, Errors_1) { | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__, exports, __webpack_require__(/*! maishu-chitu-service */ "maishu-chitu-service"), __webpack_require__(/*! ./Page */ "./out/Page.js"), __webpack_require__(/*! ./Application */ "./out/Application.js"), __webpack_require__(/*! ./Errors */ "./out/Errors.js")], __WEBPACK_AMD_DEFINE_RESULT__ = (function (require, exports, maishu_chitu_service_1, Page_1, Application_1, Errors_1) { | ||
"use strict"; | ||
@@ -582,2 +578,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this.nodes = {}; | ||
this.MAX_PAGE_COUNT = 100; | ||
this.error = maishu_chitu_service_1.Callbacks(); | ||
@@ -644,7 +641,7 @@ this.parser = parser || this.defaultPageNodeParser(); | ||
} | ||
getPage(node, values) { | ||
console.assert(node != null); | ||
getPage(pageUrl, values) { | ||
if (!pageUrl) | ||
throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
let pageName = node.name; | ||
let cachePage = this.cachePages[pageName]; | ||
let cachePage = this.cachePages[pageUrl]; | ||
if (cachePage != null) { | ||
@@ -654,12 +651,12 @@ cachePage.data = values || {}; | ||
} | ||
let page = this.createPage(pageName, values); | ||
this.cachePages[pageName] = page; | ||
let page = this.createPage(pageUrl, values); | ||
this.cachePages[pageUrl] = page; | ||
this.on_pageCreated(page); | ||
return { page, isNew: true }; | ||
} | ||
createPage(pageName, values) { | ||
if (!pageName) | ||
throw Errors_1.Errors.argumentNull('pageName'); | ||
createPage(pageUrl, values) { | ||
if (!pageUrl) | ||
throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
let element = this.createPageElement(pageName); | ||
let element = this.createPageElement(pageUrl); | ||
let displayer = new this.pageDisplayType(this); | ||
@@ -669,3 +666,3 @@ console.assert(this.pageType != null); | ||
app: this, | ||
name: pageName, | ||
url: pageUrl, | ||
data: values, | ||
@@ -694,20 +691,14 @@ displayer, | ||
} | ||
showPage(pageName, args, forceRender) { | ||
showPage(pageUrl, args, forceRender) { | ||
args = args || {}; | ||
forceRender = forceRender == null ? false : true; | ||
if (!pageName) | ||
if (!pageUrl) | ||
throw Errors_1.Errors.argumentNull('pageName'); | ||
let node = this.findSiteMapNode(pageName); | ||
if (node == null) | ||
throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
if (this.currentPage != null && this.currentPage.name == pageName) | ||
if (this.currentPage != null && this.currentPage.url == pageUrl) | ||
return this.currentPage; | ||
let { page, isNew } = this.getPage(node, args); | ||
let { page, isNew } = this.getPage(pageUrl, args); | ||
if (isNew || forceRender) { | ||
let siteMapNode = this.findSiteMapNode(pageName); | ||
if (siteMapNode == null) | ||
throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
let action = siteMapNode.action; | ||
let action = this.findPageAction(pageUrl); | ||
if (action == null) | ||
throw Errors_1.Errors.actionCanntNull(pageName); | ||
throw Errors_1.Errors.actionCanntNull(pageUrl); | ||
action(page, this); | ||
@@ -724,3 +715,3 @@ } | ||
page.close(); | ||
delete this.cachePages[page.name]; | ||
delete this.cachePages[page.url]; | ||
this.page_stack = this.page_stack.filter(o => o != page); | ||
@@ -730,3 +721,19 @@ } | ||
this.page_stack.push(page); | ||
if (this.page_stack.length > this.MAX_PAGE_COUNT) { | ||
let page = this.page_stack.shift(); | ||
if (page) | ||
this.closePage(page); | ||
} | ||
} | ||
findPageAction(pageUrl) { | ||
let routeData = Application_1.parseUrl(pageUrl); | ||
let pageName = routeData.pageName; | ||
let node = this.findSiteMapNode(pageName); | ||
if (node == null) | ||
throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
let action = node.action; | ||
if (action == null) | ||
throw Errors_1.Errors.actionCanntNull(pageName); | ||
return node.action; | ||
} | ||
findSiteMapNode(pageName) { | ||
@@ -733,0 +740,0 @@ if (this.nodes[pageName]) |
@@ -0,0 +0,0 @@ |
@@ -30,4 +30,3 @@ "use strict"; | ||
function _parseUrl(app, url) { | ||
if (!app) throw Errors_1.Errors.argumentNull('app'); | ||
function _parseUrl(url) { | ||
if (!url) throw Errors_1.Errors.argumentNull('url'); | ||
@@ -68,2 +67,4 @@ var sharpIndex = url.indexOf('#'); | ||
exports.parseUrl = _parseUrl; | ||
function pareeUrlQuery(query) { | ||
@@ -129,3 +130,3 @@ var match, | ||
var routeData = _parseUrl(this, url); | ||
var routeData = _parseUrl(url); | ||
@@ -159,3 +160,3 @@ return routeData; | ||
_this2.showPageByUrl(url, true); | ||
_this2.showPageByUrl(url); | ||
}; | ||
@@ -171,10 +172,4 @@ | ||
key: "showPageByUrl", | ||
value: function showPageByUrl(url, fromCache) { | ||
value: function showPageByUrl(url) { | ||
if (!url) throw Errors_1.Errors.argumentNull('url'); | ||
var routeData = this.parseUrl(url); | ||
if (routeData == null) { | ||
throw Errors_1.Errors.noneRouteMatched(url); | ||
} | ||
var tempPageData = this.fetchTemplatePageData(); | ||
@@ -195,10 +190,4 @@ var result = null; | ||
if (result == null || result.name != routeData.pageName) { | ||
var args = routeData.values || {}; | ||
if (tempPageData) { | ||
args = Object.assign(args, tempPageData); | ||
} | ||
result = this.showPage(routeData.pageName, args); | ||
if (result == null || result.url != url) { | ||
result = this.showPage(url); | ||
} | ||
@@ -205,0 +194,0 @@ |
@@ -9,3 +9,3 @@ "use strict"; | ||
define(["require", "exports", "maishu-chitu-service", "./Errors"], function (require, exports, maishu_chitu_service_1, Errors_1) { | ||
define(["require", "exports", "maishu-chitu-service", "./Errors", "./Application"], function (require, exports, maishu_chitu_service_1, Errors_1, Application_1) { | ||
"use strict"; | ||
@@ -33,4 +33,6 @@ | ||
this._displayer = params.displayer; | ||
this.data = params.data; | ||
this._name = params.name; | ||
var routeData = Application_1.parseUrl(params.url); | ||
this.data = Object.assign(routeData.values, params.data || {}); | ||
this._name = routeData.pageName; | ||
this._url = params.url; | ||
} | ||
@@ -127,2 +129,7 @@ | ||
}, { | ||
key: "url", | ||
get: function get() { | ||
return this._url; | ||
} | ||
}, { | ||
key: "app", | ||
@@ -129,0 +136,0 @@ get: function get() { |
@@ -37,3 +37,3 @@ "use strict"; | ||
define(["require", "exports", "maishu-chitu-service", "./Page", "./Errors"], function (require, exports, maishu_chitu_service_1, Page_1, Errors_1) { | ||
define(["require", "exports", "maishu-chitu-service", "./Page", "./Application", "./Errors"], function (require, exports, maishu_chitu_service_1, Page_1, Application_1, Errors_1) { | ||
"use strict"; | ||
@@ -59,2 +59,3 @@ | ||
this.nodes = {}; | ||
this.MAX_PAGE_COUNT = 100; | ||
this.error = maishu_chitu_service_1.Callbacks(); | ||
@@ -168,7 +169,6 @@ this.parser = parser || this.defaultPageNodeParser(); | ||
key: "getPage", | ||
value: function getPage(node, values) { | ||
console.assert(node != null); | ||
value: function getPage(pageUrl, values) { | ||
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
var pageName = node.name; | ||
var cachePage = this.cachePages[pageName]; | ||
var cachePage = this.cachePages[pageUrl]; | ||
@@ -183,4 +183,4 @@ if (cachePage != null) { | ||
var page = this.createPage(pageName, values); | ||
this.cachePages[pageName] = page; | ||
var page = this.createPage(pageUrl, values); | ||
this.cachePages[pageUrl] = page; | ||
this.on_pageCreated(page); | ||
@@ -194,8 +194,8 @@ return { | ||
key: "createPage", | ||
value: function createPage(pageName, values) { | ||
value: function createPage(pageUrl, values) { | ||
var _this3 = this; | ||
if (!pageName) throw Errors_1.Errors.argumentNull('pageName'); | ||
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
var element = this.createPageElement(pageName); | ||
var element = this.createPageElement(pageUrl); | ||
var displayer = new this.pageDisplayType(this); | ||
@@ -205,3 +205,3 @@ console.assert(this.pageType != null); | ||
app: this, | ||
name: pageName, | ||
url: pageUrl, | ||
data: values, | ||
@@ -237,11 +237,9 @@ displayer: displayer, | ||
key: "showPage", | ||
value: function showPage(pageName, args, forceRender) { | ||
value: function showPage(pageUrl, args, forceRender) { | ||
args = args || {}; | ||
forceRender = forceRender == null ? false : true; | ||
if (!pageName) throw Errors_1.Errors.argumentNull('pageName'); | ||
var node = this.findSiteMapNode(pageName); | ||
if (node == null) throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
if (this.currentPage != null && this.currentPage.name == pageName) return this.currentPage; | ||
if (!pageUrl) throw Errors_1.Errors.argumentNull('pageName'); | ||
if (this.currentPage != null && this.currentPage.url == pageUrl) return this.currentPage; | ||
var _this$getPage = this.getPage(node, args), | ||
var _this$getPage = this.getPage(pageUrl, args), | ||
page = _this$getPage.page, | ||
@@ -251,6 +249,4 @@ isNew = _this$getPage.isNew; | ||
if (isNew || forceRender) { | ||
var siteMapNode = this.findSiteMapNode(pageName); | ||
if (siteMapNode == null) throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
var action = siteMapNode.action; | ||
if (action == null) throw Errors_1.Errors.actionCanntNull(pageName); | ||
var action = this.findPageAction(pageUrl); | ||
if (action == null) throw Errors_1.Errors.actionCanntNull(pageUrl); | ||
action(page, this); | ||
@@ -269,3 +265,3 @@ } | ||
page.close(); | ||
delete this.cachePages[page.name]; | ||
delete this.cachePages[page.url]; | ||
this.page_stack = this.page_stack.filter(function (o) { | ||
@@ -279,4 +275,21 @@ return o != page; | ||
this.page_stack.push(page); | ||
if (this.page_stack.length > this.MAX_PAGE_COUNT) { | ||
var _page = this.page_stack.shift(); | ||
if (_page) this.closePage(_page); | ||
} | ||
} | ||
}, { | ||
key: "findPageAction", | ||
value: function findPageAction(pageUrl) { | ||
var routeData = Application_1.parseUrl(pageUrl); | ||
var pageName = routeData.pageName; | ||
var node = this.findSiteMapNode(pageName); | ||
if (node == null) throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
var action = node.action; | ||
if (action == null) throw Errors_1.Errors.actionCanntNull(pageName); | ||
return node.action; | ||
} | ||
}, { | ||
key: "findSiteMapNode", | ||
@@ -283,0 +296,0 @@ value: function findSiteMapNode(pageName) { |
@@ -21,2 +21,6 @@ import { IService, ServiceConstructor } from "maishu-chitu-service"; | ||
} | ||
export declare function parseUrl(url: string): { | ||
pageName: string; | ||
values: PageData; | ||
}; | ||
export declare class Application extends PageMaster { | ||
@@ -23,0 +27,0 @@ private _runned; |
@@ -6,5 +6,3 @@ define(["require", "exports", "maishu-chitu-service", "./PageMaster", "./Errors"], function (require, exports, maishu_chitu_service_1, PageMaster_1, Errors_1) { | ||
const DefaultPageName = "index"; | ||
function parseUrl(app, url) { | ||
if (!app) | ||
throw Errors_1.Errors.argumentNull('app'); | ||
function parseUrl(url) { | ||
if (!url) | ||
@@ -42,2 +40,3 @@ throw Errors_1.Errors.argumentNull('url'); | ||
} | ||
exports.parseUrl = parseUrl; | ||
function pareeUrlQuery(query) { | ||
@@ -76,3 +75,3 @@ let match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g, decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }; | ||
throw Errors_1.Errors.argumentNull('url'); | ||
let routeData = parseUrl(this, url); | ||
let routeData = parseUrl(url); | ||
return routeData; | ||
@@ -96,3 +95,3 @@ } | ||
} | ||
this.showPageByUrl(url, true); | ||
this.showPageByUrl(url); | ||
}; | ||
@@ -105,9 +104,5 @@ showPage(); | ||
} | ||
showPageByUrl(url, fromCache) { | ||
showPageByUrl(url) { | ||
if (!url) | ||
throw Errors_1.Errors.argumentNull('url'); | ||
var routeData = this.parseUrl(url); | ||
if (routeData == null) { | ||
throw Errors_1.Errors.noneRouteMatched(url); | ||
} | ||
let tempPageData = this.fetchTemplatePageData(); | ||
@@ -131,8 +126,4 @@ let result = null; | ||
} | ||
if (result == null || result.name != routeData.pageName) { | ||
let args = routeData.values || {}; | ||
if (tempPageData) { | ||
args = Object.assign(args, tempPageData); | ||
} | ||
result = this.showPage(routeData.pageName, args); | ||
if (result == null || result.url != url) { | ||
result = this.showPage(url); | ||
} | ||
@@ -139,0 +130,0 @@ return result; |
@@ -0,0 +0,0 @@ export declare class Errors { |
@@ -0,0 +0,0 @@ define(["require", "exports"], function (require, exports) { |
@@ -0,0 +0,0 @@ export { Application, PageNodeParser, Action, PageNode } from './Application'; |
@@ -0,0 +0,0 @@ define(["require", "exports", "./Application", "./PageMaster", "./Page", "maishu-chitu-service"], function (require, exports, Application_1, PageMaster_1, Page_1, maishu_chitu_service_1) { |
@@ -17,4 +17,4 @@ import { PageMaster } from "./PageMaster"; | ||
displayer: PageDisplayer; | ||
name: string; | ||
data: PageData; | ||
url: string; | ||
} | ||
@@ -26,2 +26,3 @@ export declare class Page { | ||
private _name; | ||
private _url; | ||
static tagName: string; | ||
@@ -48,2 +49,3 @@ data: PageData; | ||
readonly name: string; | ||
readonly url: string; | ||
readonly app: PageMaster; | ||
@@ -50,0 +52,0 @@ } |
@@ -1,2 +0,2 @@ | ||
define(["require", "exports", "maishu-chitu-service", "./Errors"], function (require, exports, maishu_chitu_service_1, Errors_1) { | ||
define(["require", "exports", "maishu-chitu-service", "./Errors", "./Application"], function (require, exports, maishu_chitu_service_1, Errors_1, Application_1) { | ||
"use strict"; | ||
@@ -16,4 +16,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this._displayer = params.displayer; | ||
this.data = params.data; | ||
this._name = params.name; | ||
let routeData = Application_1.parseUrl(params.url); | ||
this.data = Object.assign(routeData.values, params.data || {}); | ||
this._name = routeData.pageName; | ||
this._url = params.url; | ||
} | ||
@@ -77,2 +79,5 @@ on_showing() { | ||
} | ||
get url() { | ||
return this._url; | ||
} | ||
get app() { | ||
@@ -79,0 +84,0 @@ return this._app; |
import { Callback1, Callback2 } from "maishu-chitu-service"; | ||
import { Page, PageConstructor, PageDisplayConstructor } from "./Page"; | ||
import { PageNodeParser, PageNode, StringPropertyNames, Action } from "./Application"; | ||
import { PageNodeParser, StringPropertyNames, Action } from "./Application"; | ||
export declare class PageMaster { | ||
@@ -14,2 +14,3 @@ pageCreated: Callback1<this, Page>; | ||
private nodes; | ||
private MAX_PAGE_COUNT; | ||
error: Callback2<this, Error, Page | null>; | ||
@@ -24,8 +25,9 @@ parser: PageNodeParser; | ||
private getPage; | ||
protected createPage(pageName: string, values?: any): Page; | ||
protected createPage(pageUrl: string, values?: any): Page; | ||
protected createPageElement(pageName: string): HTMLElement; | ||
showPage(pageName: string, args?: object, forceRender?: boolean): Page; | ||
showPage(pageUrl: string, args?: object, forceRender?: boolean): Page; | ||
protected closePage(page: Page): void; | ||
private pushPage; | ||
protected findSiteMapNode(pageName: string): PageNode | null; | ||
protected findPageAction(pageUrl: string): Action; | ||
private findSiteMapNode; | ||
closeCurrentPage<T>(passData?: Pick<T, StringPropertyNames<T>>): void; | ||
@@ -32,0 +34,0 @@ protected readonly pageStack: Page[]; |
@@ -9,3 +9,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
define(["require", "exports", "maishu-chitu-service", "./Page", "./Errors"], function (require, exports, maishu_chitu_service_1, Page_1, Errors_1) { | ||
define(["require", "exports", "maishu-chitu-service", "./Page", "./Application", "./Errors"], function (require, exports, maishu_chitu_service_1, Page_1, Application_1, Errors_1) { | ||
"use strict"; | ||
@@ -23,2 +23,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this.nodes = {}; | ||
this.MAX_PAGE_COUNT = 100; | ||
this.error = maishu_chitu_service_1.Callbacks(); | ||
@@ -85,7 +86,7 @@ this.parser = parser || this.defaultPageNodeParser(); | ||
} | ||
getPage(node, values) { | ||
console.assert(node != null); | ||
getPage(pageUrl, values) { | ||
if (!pageUrl) | ||
throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
let pageName = node.name; | ||
let cachePage = this.cachePages[pageName]; | ||
let cachePage = this.cachePages[pageUrl]; | ||
if (cachePage != null) { | ||
@@ -95,12 +96,12 @@ cachePage.data = values || {}; | ||
} | ||
let page = this.createPage(pageName, values); | ||
this.cachePages[pageName] = page; | ||
let page = this.createPage(pageUrl, values); | ||
this.cachePages[pageUrl] = page; | ||
this.on_pageCreated(page); | ||
return { page, isNew: true }; | ||
} | ||
createPage(pageName, values) { | ||
if (!pageName) | ||
throw Errors_1.Errors.argumentNull('pageName'); | ||
createPage(pageUrl, values) { | ||
if (!pageUrl) | ||
throw Errors_1.Errors.argumentNull('pageUrl'); | ||
values = values || {}; | ||
let element = this.createPageElement(pageName); | ||
let element = this.createPageElement(pageUrl); | ||
let displayer = new this.pageDisplayType(this); | ||
@@ -110,3 +111,3 @@ console.assert(this.pageType != null); | ||
app: this, | ||
name: pageName, | ||
url: pageUrl, | ||
data: values, | ||
@@ -135,20 +136,14 @@ displayer, | ||
} | ||
showPage(pageName, args, forceRender) { | ||
showPage(pageUrl, args, forceRender) { | ||
args = args || {}; | ||
forceRender = forceRender == null ? false : true; | ||
if (!pageName) | ||
if (!pageUrl) | ||
throw Errors_1.Errors.argumentNull('pageName'); | ||
let node = this.findSiteMapNode(pageName); | ||
if (node == null) | ||
throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
if (this.currentPage != null && this.currentPage.name == pageName) | ||
if (this.currentPage != null && this.currentPage.url == pageUrl) | ||
return this.currentPage; | ||
let { page, isNew } = this.getPage(node, args); | ||
let { page, isNew } = this.getPage(pageUrl, args); | ||
if (isNew || forceRender) { | ||
let siteMapNode = this.findSiteMapNode(pageName); | ||
if (siteMapNode == null) | ||
throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
let action = siteMapNode.action; | ||
let action = this.findPageAction(pageUrl); | ||
if (action == null) | ||
throw Errors_1.Errors.actionCanntNull(pageName); | ||
throw Errors_1.Errors.actionCanntNull(pageUrl); | ||
action(page, this); | ||
@@ -165,3 +160,3 @@ } | ||
page.close(); | ||
delete this.cachePages[page.name]; | ||
delete this.cachePages[page.url]; | ||
this.page_stack = this.page_stack.filter(o => o != page); | ||
@@ -171,3 +166,19 @@ } | ||
this.page_stack.push(page); | ||
if (this.page_stack.length > this.MAX_PAGE_COUNT) { | ||
let page = this.page_stack.shift(); | ||
if (page) | ||
this.closePage(page); | ||
} | ||
} | ||
findPageAction(pageUrl) { | ||
let routeData = Application_1.parseUrl(pageUrl); | ||
let pageName = routeData.pageName; | ||
let node = this.findSiteMapNode(pageName); | ||
if (node == null) | ||
throw Errors_1.Errors.pageNodeNotExists(pageName); | ||
let action = node.action; | ||
if (action == null) | ||
throw Errors_1.Errors.actionCanntNull(pageName); | ||
return node.action; | ||
} | ||
findSiteMapNode(pageName) { | ||
@@ -174,0 +185,0 @@ if (this.nodes[pageName]) |
@@ -13,3 +13,3 @@ { | ||
"dependencies": { | ||
"maishu-chitu-service": "^1.1.4" | ||
"maishu-chitu-service": "^1.1.20" | ||
}, | ||
@@ -37,3 +37,3 @@ "homepage": "https://github.com/ansiboy/chitu#readme", | ||
}, | ||
"version": "2.9.26" | ||
"version": "2.10.0" | ||
} |
@@ -0,0 +0,0 @@ # CHITU |
@@ -9,2 +9,3 @@ import { IService, ServiceConstructor, Service } from "maishu-chitu-service"; | ||
export type SiteMapChildren<T extends PageNode> = { [key: string]: T } | ||
/** | ||
@@ -25,4 +26,3 @@ * 页面结点 | ||
const DefaultPageName = "index" | ||
function parseUrl(app: Application, url: string): { pageName: string, values: PageData } { | ||
if (!app) throw Errors.argumentNull('app') | ||
export function parseUrl(url: string): { pageName: string, values: PageData } { | ||
if (!url) throw Errors.argumentNull('url') | ||
@@ -128,3 +128,3 @@ | ||
let routeData = parseUrl(this, url); | ||
let routeData = parseUrl(url); | ||
return routeData; | ||
@@ -159,3 +159,3 @@ } | ||
} | ||
this.showPageByUrl(url, true); | ||
this.showPageByUrl(url); | ||
} | ||
@@ -178,9 +178,9 @@ | ||
*/ | ||
private showPageByUrl(url: string, fromCache: boolean): Page | null { | ||
private showPageByUrl(url: string): Page | null { | ||
if (!url) throw Errors.argumentNull('url'); | ||
var routeData = this.parseUrl(url); | ||
if (routeData == null) { | ||
throw Errors.noneRouteMatched(url); | ||
} | ||
// var routeData = this.parseUrl(url); | ||
// if (routeData == null) { | ||
// throw Errors.noneRouteMatched(url); | ||
// } | ||
@@ -212,8 +212,8 @@ let tempPageData = this.fetchTemplatePageData(); | ||
if (result == null || result.name != routeData.pageName) { | ||
let args = routeData.values || {}; | ||
if (tempPageData) { | ||
args = Object.assign(args, tempPageData); | ||
} | ||
result = this.showPage(routeData.pageName, args); | ||
if (result == null || result.url != url) { | ||
// let args = routeData.values || {}; | ||
// if (tempPageData) { | ||
// args = Object.assign(args, tempPageData); | ||
// } | ||
result = this.showPage(url); | ||
} | ||
@@ -220,0 +220,0 @@ return result; |
@@ -0,0 +0,0 @@ export class Errors { |
@@ -0,0 +0,0 @@ export { Application, PageNodeParser, Action, PageNode } from './Application' |
import { PageMaster } from "./PageMaster"; | ||
import { IService, ServiceConstructor, Service, Callbacks, Callback1 } from "maishu-chitu-service"; | ||
import { Errors } from "./Errors"; | ||
import { parseUrl } from "./Application"; | ||
@@ -21,4 +22,5 @@ export type PageData = { [key: string]: string | Function } | ||
displayer: PageDisplayer, | ||
name: string, | ||
// name: string, | ||
data: PageData, | ||
url: string | ||
} | ||
@@ -36,2 +38,3 @@ | ||
private _name: string | ||
private _url: string | ||
@@ -58,4 +61,6 @@ static tagName = 'div'; | ||
this._displayer = params.displayer; | ||
this.data = params.data | ||
this._name = params.name; | ||
let routeData = parseUrl(params.url) | ||
this.data = Object.assign(routeData.values, params.data || {}) | ||
this._name = routeData.pageName; | ||
this._url = params.url | ||
} | ||
@@ -136,2 +141,6 @@ private on_showing() { | ||
get url(): string { | ||
return this._url | ||
} | ||
get app() { | ||
@@ -138,0 +147,0 @@ return this._app; |
import { Callbacks, Callback1, Callback2 } from "maishu-chitu-service"; | ||
import { Page, PageConstructor, PageDisplayConstructor, PageDisplayerImplement } from "./Page"; | ||
import { PageNodeParser, PageNode, StringPropertyNames, Action } from "./Application"; | ||
import { PageNodeParser, PageNode, StringPropertyNames, Action, parseUrl } from "./Application"; | ||
import { Errors } from "./Errors"; | ||
@@ -25,6 +25,7 @@ | ||
private cachePages: { [name: string]: Page } = {}; | ||
private cachePages: { [pageUrl: string]: Page } = {}; | ||
private page_stack = new Array<Page>(); | ||
private container: HTMLElement; | ||
private nodes: { [name: string]: PageNode } = {} | ||
private MAX_PAGE_COUNT = 100 | ||
@@ -119,15 +120,14 @@ /** | ||
private getPage(node: PageNode, values?: any): { page: Page, isNew: boolean } { | ||
console.assert(node != null); | ||
private getPage(pageUrl: string, values?: any): { page: Page, isNew: boolean } { | ||
if (!pageUrl) throw Errors.argumentNull('pageUrl') | ||
values = values || {}; | ||
let pageName = node.name; | ||
let cachePage = this.cachePages[pageName]; | ||
let cachePage = this.cachePages[pageUrl]; | ||
if (cachePage != null) { | ||
cachePage.data = values || {} //Object.assign(cachePage.data || {}, values); | ||
cachePage.data = values || {} | ||
return { page: cachePage, isNew: false }; | ||
} | ||
let page = this.createPage(pageName, values); | ||
this.cachePages[pageName] = page; | ||
let page = this.createPage(pageUrl, values); | ||
this.cachePages[pageUrl] = page; | ||
@@ -138,6 +138,6 @@ this.on_pageCreated(page); | ||
protected createPage(pageName: string, values?: any): Page { | ||
if (!pageName) throw Errors.argumentNull('pageName') | ||
protected createPage(pageUrl: string, values?: any): Page { | ||
if (!pageUrl) throw Errors.argumentNull('pageUrl') | ||
values = values || {} | ||
let element = this.createPageElement(pageName); | ||
let element = this.createPageElement(pageUrl); | ||
let displayer = new this.pageDisplayType(this); | ||
@@ -148,3 +148,3 @@ | ||
app: this, | ||
name: pageName, | ||
url: pageUrl, | ||
data: values, | ||
@@ -180,7 +180,7 @@ displayer, | ||
* 显示页面 | ||
* @param pageName 页面名称 | ||
* @param pageUrl 页面名称 | ||
* @param args 传递给页面的参数 | ||
* @param forceRender 是否强制重新渲染页面,是表示强制重新渲染 | ||
*/ | ||
public showPage(pageName: string, args?: object, forceRender?: boolean): Page { | ||
public showPage(pageUrl: string, args?: object, forceRender?: boolean): Page { | ||
@@ -190,20 +190,12 @@ args = args || {} | ||
if (!pageName) throw Errors.argumentNull('pageName'); | ||
if (!pageUrl) throw Errors.argumentNull('pageName'); | ||
let node = this.findSiteMapNode(pageName); | ||
if (node == null) | ||
throw Errors.pageNodeNotExists(pageName) | ||
if (this.currentPage != null && this.currentPage.name == pageName) | ||
if (this.currentPage != null && this.currentPage.url == pageUrl) | ||
return this.currentPage; | ||
let { page, isNew } = this.getPage(node, args); | ||
let { page, isNew } = this.getPage(pageUrl, args); | ||
if (isNew || forceRender) { | ||
let siteMapNode = this.findSiteMapNode(pageName); | ||
if (siteMapNode == null) | ||
throw Errors.pageNodeNotExists(pageName); | ||
let action = siteMapNode.action; | ||
let action = this.findPageAction(pageUrl) | ||
if (action == null) | ||
throw Errors.actionCanntNull(pageName); | ||
throw Errors.actionCanntNull(pageUrl); | ||
@@ -228,3 +220,3 @@ action(page, this) | ||
delete this.cachePages[page.name]; | ||
delete this.cachePages[page.url]; | ||
this.page_stack = this.page_stack.filter(o => o != page); | ||
@@ -235,5 +227,24 @@ } | ||
this.page_stack.push(page); | ||
if (this.page_stack.length > this.MAX_PAGE_COUNT) { | ||
let page = this.page_stack.shift() | ||
if (page) | ||
this.closePage(page) | ||
} | ||
} | ||
protected findSiteMapNode(pageName: string): PageNode | null { | ||
protected findPageAction(pageUrl: string): Action { | ||
let routeData = parseUrl(pageUrl) | ||
let pageName = routeData.pageName | ||
let node = this.findSiteMapNode(pageName) | ||
if (node == null) | ||
throw Errors.pageNodeNotExists(pageName) | ||
let action = node.action; | ||
if (action == null) | ||
throw Errors.actionCanntNull(pageName); | ||
return node.action | ||
} | ||
private findSiteMapNode(pageName: string): PageNode | null { | ||
if (this.nodes[pageName]) | ||
@@ -268,3 +279,2 @@ return this.nodes[pageName] | ||
// page.close(); | ||
this.closePage(page) | ||
@@ -271,0 +281,0 @@ if (this.currentPage) { |
@@ -0,0 +0,0 @@ // Type definitions for RequireJS 2.1.8 |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ const webpack = require('webpack'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6511
391904
Updatedmaishu-chitu-service@^1.1.20