Skip to content

Commit

Permalink
Added namespace support for auto fetching the methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Feb 6, 2018
1 parent cd6f9f9 commit f8634fe
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
6 changes: 3 additions & 3 deletions dist/hprose-html5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/hprose-html5.min.js

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions dist/hprose-html5.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -4064,7 +4064,7 @@ hprose.global = (
* *
* hprose client for HTML5. *
* *
* LastModified: Aug 20, 2017 *
* LastModified: Feb 6, 2018 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -4207,6 +4207,27 @@ hprose.global = (
return null;
}

function normalizeFunctions(functions) {
var root = [Object.create(null)];
for (var i in functions) {
var func = functions[i].split('_');
var n = func.length - 1;
if (n > 0) {
var node = root;
for (var j = 0; j < n; j++) {
var f = func[j];
if (node[0][f] === undefined) {
node[0][f] = [Object.create(null)];
}
node = node[0][f];
}
node.push(func[n]);
}
root.push(functions[i]);
}
return root;
}

function initService(stub) {
var context = {
retry: _retry,
Expand All @@ -4228,7 +4249,7 @@ hprose.global = (
error = new Error(reader.readString());
break;
case Tags.TagFunctions:
var functions = reader.readList();
var functions = normalizeFunctions(reader.readList());
reader.checkTag(Tags.TagEnd);
setFunctions(stub, functions);
break;
Expand Down
25 changes: 23 additions & 2 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* *
* hprose client for HTML5. *
* *
* LastModified: Aug 20, 2017 *
* LastModified: Feb 6, 2018 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -155,6 +155,27 @@
return null;
}

function normalizeFunctions(functions) {
var root = [Object.create(null)];
for (var i in functions) {
var func = functions[i].split('_');
var n = func.length - 1;
if (n > 0) {
var node = root;
for (var j = 0; j < n; j++) {
var f = func[j];
if (node[0][f] === undefined) {
node[0][f] = [Object.create(null)];
}
node = node[0][f];
}
node.push(func[n]);
}
root.push(functions[i]);
}
return root;
}

function initService(stub) {
var context = {
retry: _retry,
Expand All @@ -176,7 +197,7 @@
error = new Error(reader.readString());
break;
case Tags.TagFunctions:
var functions = reader.readList();
var functions = normalizeFunctions(reader.readList());
reader.checkTag(Tags.TagEnd);
setFunctions(stub, functions);
break;
Expand Down
2 changes: 1 addition & 1 deletion test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script type="text/javascript" src="../dist/hprose-html5.js"></script>
</head>
<script type="text/javascript">
var client = new hprose.HttpClient("http://www.hprose.com/example/", ["hello"]);
var client = new hprose.HttpClient("http://www.hprose.com/example/index.php", ["hello"]);
client.hello("World!", function(result) {
alert(result);
}, function(name, err) {
Expand Down
2 changes: 1 addition & 1 deletion test/test_sea.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
});
seajs.use('hprose', function(hprose) {
var client = new hprose.HttpClient("http://www.hprose.com/example/", ["hello"]);
var client = new hprose.HttpClient("http://www.hprose.com/example/index.php", ["hello"]);
client.hello("World!", function(result) {
alert(result);
}, function(name, err) {
Expand Down

0 comments on commit f8634fe

Please sign in to comment.