grpc-getting-started
Advanced tools
Comparing version 0.3.6 to 0.3.7
@@ -5,3 +5,3 @@ { | ||
"name": "grpc-getting-started", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"main": "none", | ||
@@ -8,0 +8,0 @@ "description": "Demonstration of the use of gRPC and front-end", |
@@ -208,3 +208,3 @@ # gRPC 入门指引 (最初版) | ||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, { | ||
keepCase: true, | ||
keepCase: true, // 如果使用 `keepUserse`, 数据将采用驼峰命名 | ||
longs: String, | ||
@@ -211,0 +211,0 @@ enums: String, |
@@ -214,3 +214,3 @@ # gRPC Getting Started (original version) | ||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, { | ||
keepCase: true, | ||
keepCase: true, // Use `keepUserse` to format JSON to camelCase | ||
longs: String, | ||
@@ -217,0 +217,0 @@ enums: String, |
@@ -67,3 +67,3 @@ # gRPC Getting Started | ||
```sh | ||
$ build:api-prod | ||
$ npm run build:api-prod | ||
``` | ||
@@ -73,3 +73,3 @@ or | ||
```sh | ||
$ build:api-dev | ||
$ npm run build:api-dev | ||
``` | ||
@@ -76,0 +76,0 @@ |
import SendInfoService from '../client/sendInfo'; | ||
import PostService from '../client/post'; | ||
export { | ||
SendInfoService | ||
SendInfoService, | ||
PostService | ||
} |
import { SaveArrListReq, ArrData } from '../proto/array_pb.js'; | ||
import { ArrayServiceClient } from '../proto/array_pb_service.js'; | ||
import { cancelRun } from './utils/grpc-api-assistant'; | ||
const client = new ArrayServiceClient('http://' + window.location.hostname + ':12345', null, null); | ||
@@ -17,4 +19,19 @@ | ||
// Both save and add can achieve the same result | ||
class UtilsArray { | ||
class ArrayService { | ||
constructor() { | ||
this.callArrayServiceAddArrList = null; | ||
this.callArrayServiceSaveArrList = null; | ||
} | ||
cancelAbortControllerArrayServiceAddArrList() { | ||
cancelRun(this.callArrayServiceAddArrList, 'ArrayServiceAddArrList'); | ||
} | ||
cancelAbortControllerArrayServiceSaveArrList() { | ||
cancelRun(this.callArrayServiceSaveArrList, 'ArrayServiceSaveArrList'); | ||
} | ||
todoArrAdd(arr_id, title, desc) { | ||
@@ -37,3 +54,3 @@ const req = new SaveArrListReq(); | ||
client.saveArrList(req, { | ||
this.callArrayServiceAddArrList = client.saveArrList(req, { | ||
'session-id': 'xxxx-xxxx-xxxxx' | ||
@@ -75,3 +92,3 @@ }, function (err, response) { | ||
client.saveArrList(req, { | ||
this.callArrayServiceSaveArrList = client.saveArrList(req, { | ||
'session-id': 'xxxx-xxxx-xxxxx' | ||
@@ -118,3 +135,3 @@ }, function (err, response) { | ||
export default new UtilsArray; | ||
export default new ArrayService; | ||
@@ -1,6 +0,6 @@ | ||
import UtilsSendInfo from './sendInfo'; | ||
import UtilsPost from './post'; | ||
import SendinfoService from './sendInfo'; | ||
import PostService from './post'; | ||
document.body.appendChild(UtilsSendInfo.createSendForm()); | ||
document.body.appendChild(UtilsPost.createPostForm()); | ||
document.body.appendChild(SendinfoService.createSendForm()); | ||
document.body.appendChild(PostService.createPostForm()); | ||
@@ -13,3 +13,3 @@ | ||
UtilsSendInfo.sendInfo(document.getElementById('input1').value, document.getElementById('input2').value).then(function (data) { | ||
SendinfoService.sendInfo(document.getElementById('input1').value, document.getElementById('input2').value).then(function (data) { | ||
document.getElementById('formstatus').innerHTML = `${data}`; | ||
@@ -26,4 +26,4 @@ }); | ||
e.preventDefault(); | ||
UtilsPost.getPostList().then(function (response) { | ||
UtilsPost.generateList(response.data); | ||
PostService.getPostList().then(function (response) { | ||
PostService.generateList(response.data); | ||
}); | ||
@@ -37,5 +37,5 @@ }); | ||
UtilsPost.addNewPost().then(function (addrResponse) { | ||
UtilsPost.getPostList().then(function (response) { | ||
UtilsPost.generateList(response.data); | ||
PostService.addNewPost().then(function (addrResponse) { | ||
PostService.getPostList().then(function (response) { | ||
PostService.generateList(response.data); | ||
}); | ||
@@ -51,5 +51,5 @@ }); | ||
UtilsPost.findPost().then(function (response) { | ||
PostService.findPost().then(function (response) { | ||
console.log('findPost: ', response); | ||
UtilsPost.generateList(response.data); | ||
PostService.generateList(response.data); | ||
}); | ||
@@ -56,0 +56,0 @@ }); |
@@ -5,2 +5,5 @@ import { PostList, Post, PostRow, FilterId } from '../proto/post_pb.js'; | ||
import { cancelRun } from './utils/grpc-api-assistant'; | ||
const client = new PostServiceClient('http://' + window.location.hostname + ':12345', null, null); | ||
@@ -18,8 +21,28 @@ | ||
class UtilsPost { | ||
class PostService { | ||
constructor() { | ||
this.callPostServiceGetPost = null; | ||
this.callPostServiceAddPost = null; | ||
this.callPostServiceFindId = null; | ||
} | ||
cancelAbortControllerPostServiceGetPost() { | ||
cancelRun(this.callPostServiceGetPost, 'PostServiceGetPost'); | ||
} | ||
cancelAbortControllerPostServiceAddPost() { | ||
cancelRun(this.callPostServiceAddPost, 'PostServiceAddPost'); | ||
} | ||
cancelAbortControllerPostServiceFindId() { | ||
cancelRun(this.callPostServiceFindId, 'PostServiceFindId'); | ||
} | ||
todoList() { | ||
return new Promise((resolve, reject) => { | ||
client.getPost(new Empty(), function (err, response) { | ||
this.callPostServiceGetPost = client.getPost(new Empty(), function (err, response) { | ||
if (err) { | ||
@@ -57,5 +80,5 @@ resolve(err); | ||
return new Promise((resolve, reject) => { | ||
const stream = client.addPost((err, res) => { | ||
this.callPostServiceAddPost = client.addPost((err, res) => { | ||
if (err) { | ||
stream.end(); | ||
this.callPostServiceAddPost.end(); | ||
reject(); | ||
@@ -65,3 +88,3 @@ } | ||
stream.write(streamReq); | ||
this.callPostServiceAddPost.write(streamReq); | ||
resolve(); | ||
@@ -78,9 +101,9 @@ | ||
const stream = client.findId(req); | ||
this.callPostServiceFindId = client.findId(req); | ||
let data = null; | ||
stream.on('data', (res) => { | ||
this.callPostServiceFindId.on('data', (res) => { | ||
console.log('stream.on("data") res 1: ', res.getItemsListList()); | ||
data = res.getItemsListList(); | ||
}); | ||
stream.on('end', (res) => { | ||
this.callPostServiceFindId.on('end', (res) => { | ||
console.log('stream.on("end") res 2: ', res); | ||
@@ -244,4 +267,4 @@ // {"code":0,"details":"OK","metadata":{"headersMap":{"grpc-status":["0"],"grpc-message":["OK"]}}} | ||
export default new UtilsPost; | ||
export default new PostService; | ||
import { HelloRequest } from '../proto/example_pb.js'; | ||
import { HelloServiceClient } from '../proto/example_pb_service.js'; | ||
import { cancelRun } from './utils/grpc-api-assistant'; | ||
@@ -15,4 +16,12 @@ const client = new HelloServiceClient('http://' + window.location.hostname + ':12345', null, null); | ||
class UtilsSendInfo { | ||
class SendinfoService { | ||
constructor() { | ||
this.callSendinfoService = null; | ||
} | ||
cancelAbortControllerSendinfoService() { | ||
cancelRun(this.callSendinfoService, 'SendinfoService'); | ||
} | ||
todoSend(str1, str2) { | ||
@@ -25,3 +34,3 @@ | ||
client.getHelloReq(req, function (err, response) { | ||
this.callSendinfoService = client.getHelloReq(req, function (err, response) { | ||
if (err) { | ||
@@ -98,2 +107,2 @@ resolve(err); | ||
export default new UtilsSendInfo; | ||
export default new SendinfoService; |
@@ -13,3 +13,3 @@ | ||
const loadConfig = { | ||
keepCase: true, | ||
keepCase: true, // Use `keepUserse` to format JSON to camelCase | ||
longs: String, | ||
@@ -16,0 +16,0 @@ enums: String, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
2366668
48
3023