grpc-getting-started
Advanced tools
Comparing version 0.3.1 to 0.3.3
@@ -5,3 +5,3 @@ { | ||
"name": "grpc-getting-started", | ||
"version": "0.3.1", | ||
"version": "0.3.3", | ||
"main": "none", | ||
@@ -8,0 +8,0 @@ "description": "Demonstration of the use of gRPC and front-end", |
@@ -21,12 +21,12 @@ import UtilsSendInfo from './sendInfo'; | ||
// get post list | ||
// get post list (you can use `async...await`) | ||
//============================== | ||
document.getElementById('btnGetPosts').addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
UtilsPost.getPostList().then(function (data) { | ||
UtilsPost.generateList(data); | ||
UtilsPost.getPostList().then(function (response) { | ||
UtilsPost.generateList(response.data); | ||
}); | ||
}); | ||
// add new post | ||
// add new post (you can use `async...await`) | ||
//============================== | ||
@@ -36,6 +36,6 @@ document.getElementById('btnAddPost').addEventListener('click', (e) => { | ||
UtilsPost.addNewPost().then(function (data) { | ||
console.log(data); | ||
UtilsPost.getPostList().then(function (data) { | ||
UtilsPost.generateList(data); | ||
UtilsPost.addNewPost().then(function (addrResponse) { | ||
console.log(addrResponse); | ||
UtilsPost.getPostList().then(function (response) { | ||
UtilsPost.generateList(response.data); | ||
}); | ||
@@ -46,3 +46,3 @@ }); | ||
// find post via ID | ||
// find post via ID (you can use `async...await`) | ||
//============================== | ||
@@ -52,5 +52,5 @@ document.getElementById('btnFindId').addEventListener('click', (e) => { | ||
UtilsPost.findPost().then(function (data) { | ||
console.log(data); | ||
UtilsPost.generateList(data); | ||
UtilsPost.findPost().then(function (response) { | ||
console.log(response); | ||
UtilsPost.generateList(response.data); | ||
}); | ||
@@ -57,0 +57,0 @@ }); |
@@ -6,2 +6,11 @@ import { PostList, Post, PostRow, FilterId } from '../proto/post_pb.js'; | ||
// grpc fault tolerance | ||
const grpcError = (data) => { | ||
if ( typeof data === 'undefined' ) return; | ||
if ( data.toString() === 'Error' ) { | ||
localStorage.removeItem('XXX_XXX_XXX'); | ||
document.cookie = `XXX_XXX_XXX=null;expires=${new Date(0).toUTCString()};path=/`; | ||
} | ||
}; | ||
@@ -19,3 +28,7 @@ class UtilsPost { | ||
} else { | ||
resolve(response.getItemsListList()); | ||
resolve({ | ||
code: 0, | ||
message: '', | ||
data: response.getItemsListList() | ||
}) | ||
} | ||
@@ -73,3 +86,7 @@ }); | ||
resolve(data); | ||
resolve({ | ||
code: 0, | ||
message: '', | ||
data: data | ||
}) | ||
}); | ||
@@ -141,8 +158,14 @@ | ||
// If a grpc connection error occurs | ||
// User needs to log in again | ||
grpcError(data); | ||
// | ||
const res = []; | ||
data.forEach((item, i) => { | ||
const resList = []; | ||
for (const item of data.data) { | ||
const postProperty = item.getPostProperty(); | ||
res.push( | ||
resList.push( | ||
{ | ||
@@ -159,4 +182,11 @@ 'postId': item.getId(), | ||
); | ||
}); | ||
return res; | ||
} | ||
return { | ||
code: data.code, | ||
message: data.message, | ||
data: resList | ||
}; | ||
} | ||
@@ -166,2 +196,7 @@ | ||
const data = await this.todoAdd(); | ||
// If a grpc connection error occurs | ||
// User needs to log in again | ||
grpcError(data); | ||
return data; | ||
@@ -172,8 +207,15 @@ } | ||
const data = await this.todoFindId(); | ||
// If a grpc connection error occurs | ||
// User needs to log in again | ||
grpcError(data); | ||
// | ||
const res = []; | ||
data.forEach((item, i) => { | ||
const resList = []; | ||
for (const item of data.data) { | ||
const postProperty = item.getPostProperty(); | ||
res.push( | ||
resList.push( | ||
{ | ||
@@ -188,6 +230,12 @@ 'postId': item.getId(), | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
return res; | ||
} | ||
return { | ||
code: data.code, | ||
message: data.message, | ||
data: resList | ||
}; | ||
} | ||
@@ -194,0 +242,0 @@ |
@@ -7,2 +7,9 @@ import { HelloRequest } from '../proto/example_pb.js'; | ||
// grpc fault tolerance | ||
const grpcError = (data) => { | ||
if ( data.toString() === 'Error' ) { | ||
localStorage.removeItem('XXX_XXX_XXX'); | ||
document.cookie = `XXX_XXX_XXX=null;expires=${new Date(0).toUTCString()};path=/`; | ||
} | ||
}; | ||
@@ -79,2 +86,7 @@ class UtilsSendInfo { | ||
const data = await this.todoSend(str1, str2); | ||
// If a grpc connection error occurs | ||
// User needs to log in again | ||
grpcError(data); | ||
return data; | ||
@@ -81,0 +93,0 @@ } |
@@ -95,3 +95,14 @@ | ||
call.on('data', (item) => { | ||
postsData.push(item); // { id: xxx, title: 'New Post Title xxx' , catName: 'newtype' } | ||
/* | ||
// item: | ||
{ | ||
id: 66, | ||
title: 'New Post Title 66', | ||
cat_name: 'newtype', | ||
post_property: { post_id: '66', post_path: '/example66' }, | ||
log_name: 'newlog', | ||
_log_name: 'log_name' | ||
} | ||
*/ | ||
postsData.push(item); | ||
}); | ||
@@ -98,0 +109,0 @@ call.on('end', () => callback(null, new Empty())); |
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
2025931
30
2023