Commit adc123f3 authored by Arthur Verschaeve's avatar Arthur Verschaeve

Merge pull request #1302 from tastejs/sjs/fix-webrx

webrx fixes
parents 0b3a583c b4cb63db
...@@ -123,12 +123,9 @@ ...@@ -123,12 +123,9 @@
// setup routing // setup routing
var self = this; var self = this;
// Configure the Base-Url for all states (in a production-setup you would probably
// pass this from server to client via a custom query-parameter or something similar)
wx.router.baseUrl = '/examples/webrx/';
wx.router.state({ wx.router.state({
name: '$', name: '$',
url: '/examples/webrx/',
onEnter: function () { onEnter: function () {
self.showMode(displayModeAll); self.showMode(displayModeAll);
} }
......
...@@ -114,7 +114,12 @@ ...@@ -114,7 +114,12 @@
})({}); })({});
if (location.hostname === 'todomvc.com') { if (location.hostname === 'todomvc.com') {
window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-31081062-1', 'auto');
ga('send', 'pageview');
} }
/* jshint ignore:end */ /* jshint ignore:end */
...@@ -228,7 +233,7 @@ ...@@ -228,7 +233,7 @@
xhr.onload = function (e) { xhr.onload = function (e) {
var parsedResponse = JSON.parse(e.target.responseText); var parsedResponse = JSON.parse(e.target.responseText);
if (parsedResponse instanceof Array) { if (parsedResponse instanceof Array) {
var count = parsedResponse.length var count = parsedResponse.length;
if (count !== 0) { if (count !== 0) {
issueLink.innerHTML = 'This app has ' + count + ' open issues'; issueLink.innerHTML = 'This app has ' + count + ' open issues';
document.getElementById('issue-count').style.display = 'inline'; document.getElementById('issue-count').style.display = 'inline';
......
var wx; var wx;
(function (wx) {
"use strict";
})(wx || (wx = {}));
var wx;
(function (wx) { (function (wx) {
"use strict"; "use strict";
var WeakMapEmulated = (function () { var WeakMapEmulated = (function () {
...@@ -59,10 +63,6 @@ var wx; ...@@ -59,10 +63,6 @@ var wx;
"use strict"; "use strict";
})(wx || (wx = {})); })(wx || (wx = {}));
var wx; var wx;
(function (wx) {
"use strict";
})(wx || (wx = {}));
var wx;
(function (wx) { (function (wx) {
var internal; var internal;
(function (internal) { (function (internal) {
...@@ -104,7 +104,7 @@ var wx; ...@@ -104,7 +104,7 @@ var wx;
var wx; var wx;
(function (wx) { (function (wx) {
"use strict"; "use strict";
var cssClassNameRegex = /\S+/g; var regexCssClassName = /\S+/g;
var RxObsConstructor = Rx.Observable; var RxObsConstructor = Rx.Observable;
wx.noop = function () { wx.noop = function () {
}; };
...@@ -163,6 +163,20 @@ var wx; ...@@ -163,6 +163,20 @@ var wx;
return false; return false;
} }
wx.isInUnitTest = isInUnitTest; wx.isInUnitTest = isInUnitTest;
function getSearchParameters(query) {
query = query || wx.app.history.location.search.substr(1);
if (query) {
var result = {};
var params = query.split("&");
for (var i = 0; i < params.length; i++) {
var tmp = params[i].split("=");
result[tmp[0]] = decodeURIComponent(tmp[1]);
}
return result;
}
return {};
}
wx.getSearchParameters = getSearchParameters;
function args2Array(args) { function args2Array(args) {
var result = []; var result = [];
for (var i = 0, len = args.length; i < len; i++) { for (var i = 0, len = args.length; i < len; i++) {
...@@ -246,7 +260,7 @@ var wx; ...@@ -246,7 +260,7 @@ var wx;
classNames[_i - 2] = arguments[_i]; classNames[_i - 2] = arguments[_i];
} }
if (classNames) { if (classNames) {
var currentClassNames = node.className.match(cssClassNameRegex) || []; var currentClassNames = node.className.match(regexCssClassName) || [];
var index; var index;
var i; var i;
var className; var className;
...@@ -4581,6 +4595,100 @@ var wx; ...@@ -4581,6 +4595,100 @@ var wx;
wx.list = list; wx.list = list;
})(wx || (wx = {})); })(wx || (wx = {}));
var wx; var wx;
(function (wx) {
"use strict";
var MapEmulated = (function () {
function MapEmulated() {
this.cacheSentinel = {};
this.keys = [];
this.values = [];
this.cache = this.cacheSentinel;
}
Object.defineProperty(MapEmulated.prototype, "size", {
get: function () {
return this.keys.length;
},
enumerable: true,
configurable: true
});
MapEmulated.prototype.has = function (key) {
if (key === this.cache) {
return true;
}
if (this.find(key) >= 0) {
this.cache = key;
return true;
}
return false;
};
MapEmulated.prototype.get = function (key) {
var index = this.find(key);
if (index >= 0) {
this.cache = key;
return this.values[index];
}
return undefined;
};
MapEmulated.prototype.set = function (key, value) {
this.delete(key);
this.keys.push(key);
this.values.push(value);
this.cache = key;
return this;
};
MapEmulated.prototype.delete = function (key) {
var index = this.find(key);
if (index >= 0) {
this.keys.splice(index, 1);
this.values.splice(index, 1);
this.cache = this.cacheSentinel;
return true;
}
return false;
};
MapEmulated.prototype.clear = function () {
this.keys.length = 0;
this.values.length = 0;
this.cache = this.cacheSentinel;
};
MapEmulated.prototype.forEach = function (callback, thisArg) {
var size = this.size;
for (var i = 0; i < size; ++i) {
var key = this.keys[i];
var value = this.values[i];
this.cache = key;
callback.call(this, value, key, this);
}
};
Object.defineProperty(MapEmulated.prototype, "isEmulated", {
get: function () {
return true;
},
enumerable: true,
configurable: true
});
MapEmulated.prototype.find = function (key) {
var keys = this.keys;
var size = keys.length;
for (var i = 0; i < size; ++i) {
if (keys[i] === key) {
return i;
}
}
return -1;
};
return MapEmulated;
})();
var hasNativeSupport = typeof Map === "function" && Map.prototype.hasOwnProperty("forEach") && Map.prototype.hasOwnProperty("add") && Map.prototype.hasOwnProperty("clear") && Map.prototype.hasOwnProperty("devare") && Map.prototype.hasOwnProperty("has");
function createMap(disableNativeSupport) {
if (disableNativeSupport || !hasNativeSupport) {
return new MapEmulated();
}
return new Map();
}
wx.createMap = createMap;
})(wx || (wx = {}));
var wx;
(function (wx) { (function (wx) {
"use strict"; "use strict";
var groupId = 0; var groupId = 0;
...@@ -6642,7 +6750,6 @@ var wx; ...@@ -6642,7 +6750,6 @@ var wx;
var Router = (function () { var Router = (function () {
function Router(domManager) { function Router(domManager) {
var _this = this; var _this = this;
this.baseUrl = "/";
this.current = wx.property(); this.current = wx.property();
this.states = {}; this.states = {};
this.pathSeparator = "."; this.pathSeparator = ".";
...@@ -6650,7 +6757,7 @@ var wx; ...@@ -6650,7 +6757,7 @@ var wx;
this.rootStateName = "$"; this.rootStateName = "$";
this.validPathRegExp = /^[a-zA-Z]([\w-_]*$)/; this.validPathRegExp = /^[a-zA-Z]([\w-_]*$)/;
this.domManager = domManager; this.domManager = domManager;
this.reset(); this.reset(false);
wx.app.history.onPopState.subscribe(function (e) { wx.app.history.onPopState.subscribe(function (e) {
var state = e.state; var state = e.state;
var stateName = state.stateName; var stateName = state.stateName;
...@@ -6661,6 +6768,7 @@ var wx; ...@@ -6661,6 +6768,7 @@ var wx;
}); });
wx.app.title.changed.subscribe(function (x) { wx.app.title.changed.subscribe(function (x) {
document.title = x; document.title = x;
if (_this.current() != null)
_this.replaceHistoryState(_this.current(), x); _this.replaceHistoryState(_this.current(), x);
}); });
} }
...@@ -6727,30 +6835,45 @@ var wx; ...@@ -6727,30 +6835,45 @@ var wx;
return route.stringify(params); return route.stringify(params);
return null; return null;
}; };
Router.prototype.reset = function () { Router.prototype.reset = function (enterRootState) {
if (enterRootState === void 0) { enterRootState = true; }
this.states = {}; this.states = {};
this.root = this.registerStateInternal({ this.root = this.registerStateInternal({
name: this.rootStateName, name: this.rootStateName,
route: wx.route(this.baseUrl) url: wx.route("/")
}); });
if (enterRootState)
this.go(this.rootStateName, {}, { location: 2 /* replace */ }); this.go(this.rootStateName, {}, { location: 2 /* replace */ });
}; };
Router.prototype.sync = function () { Router.prototype.sync = function (url) {
var uri = wx.app.history.location.pathname; if (url == null)
url = wx.app.history.location.pathname;
var keys = Object.keys(this.states); var keys = Object.keys(this.states);
var length = keys.length; var length = keys.length;
var params; var params;
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
var state = this.states[keys[i]]; var state = this.states[keys[i]];
var route = this.getAbsoluteRouteForState(state.name); var route = this.getAbsoluteRouteForState(state.name);
if ((params = route.parse(uri)) != null) { if ((params = route.parse(url)) != null) {
this.go(state.name, params, { location: 2 /* replace */ }); this.go(state.name, params, { location: 2 /* replace */ });
break; return;
} }
} }
if (this.current() == null)
this.reload();
}; };
Router.prototype.reload = function () { Router.prototype.reload = function () {
this.go(this.current().name, this.current().params, { force: true, location: false }); var state;
var params;
if (this.current() != null) {
state = this.current().name;
params = this.current().params;
}
else {
state = this.rootStateName;
params = {};
}
this.go(state, params, { force: true, location: 2 /* replace */ });
}; };
Router.prototype.getViewComponent = function (viewName) { Router.prototype.getViewComponent = function (viewName) {
var _current = this.current(); var _current = this.current();
...@@ -6794,16 +6917,16 @@ var wx; ...@@ -6794,16 +6917,16 @@ var wx;
} }
state = wx.extend(state, {}); state = wx.extend(state, {});
this.states[state.name] = state; this.states[state.name] = state;
if (state.route != null) { if (state.url != null) {
if (typeof state.route === "string") { if (typeof state.url === "string") {
state.route = wx.route(state.route); state.url = wx.route(state.url);
} }
} }
else { else {
if (state.name !== this.rootStateName) if (state.name !== this.rootStateName)
state.route = wx.route(parts[parts.length - 1]); state.url = wx.route(parts[parts.length - 1]);
else else
state.route = wx.route(this.baseUrl); state.url = wx.route("/");
} }
if (state.name === this.rootStateName) if (state.name === this.rootStateName)
this.root = state; this.root = state;
...@@ -6862,7 +6985,7 @@ var wx; ...@@ -6862,7 +6985,7 @@ var wx;
if (state == null) { if (state == null) {
state = { state = {
name: stateName, name: stateName,
route: wx.route(stateName) url: wx.route(stateName)
}; };
} }
result.push(state); result.push(state);
...@@ -6874,14 +6997,14 @@ var wx; ...@@ -6874,14 +6997,14 @@ var wx;
var result = null; var result = null;
hierarchy.forEach(function (state) { hierarchy.forEach(function (state) {
if (result != null) { if (result != null) {
var route = state.route; var route = state.url;
if (!route.isAbsolute) if (!route.isAbsolute)
result = result.concat(state.route); result = result.concat(state.url);
else else
result = route; result = route;
} }
else { else {
result = state.route; result = state.url;
} }
}); });
return result; return result;
...@@ -6957,7 +7080,7 @@ var wx; ...@@ -6957,7 +7080,7 @@ var wx;
} }
}); });
result = Object.keys(stateParams); result = Object.keys(stateParams);
result = result.concat(config.route.params); result = result.concat(config.url.params);
} }
return result; return result;
}; };
...@@ -6985,6 +7108,6 @@ var wx; ...@@ -6985,6 +7108,6 @@ var wx;
})(wx || (wx = {})); })(wx || (wx = {}));
var wx; var wx;
(function (wx) { (function (wx) {
wx.version = '0.9.79'; wx.version = '0.9.83';
})(wx || (wx = {})); })(wx || (wx = {}));
//# sourceMappingURL=web.rx.js.map //# sourceMappingURL=web.rx.js.map
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment