emi*_*l14 7 design-patterns reactjs grpc redux grpc-web
我有一个react-redux应用程序,我的团队使用grpc-web。我想知道 - 设计这种系统的最佳方法是什么?
目前的计划是创建 3 个抽象级别:
API模块 -grpc-web客户端周围的promisified包装器Redux thunks level - 处理 API 的异步动作创建者React components props - 只会询问组件需要什么所以components一无所知grpc,他们与动作创建者混在一起,动作创建者一无所知grpc,他们处理一个api模块,并且只有api模块与grpc-web存根一起使用。
我想走这条路的原因:
我的问题是:
grpc-webAPI是个好主意吗?如果是,编写一个函数并即时执行是否是个好主意?grpc-webAPI,因为这个 API 将来可能会改变小智 0
我在 redux thunk 上使用 grpc-web,下面的示例代码来自操作创建者:
export const getStudentInfo = (id) => async dispatch => {
const request = new StudentRequest();
request.setId("555");
var metadata = { 'token': 'value1' };
var URL = "https://localhost:5001";
var client = new StudentClient(URL);
var call = client.getStudentInformation(request, metadata, function (err, response) {
    if (err) {
        console.log(err.code);
        console.log(err.message);
    } else {
        dispatch({ type: STUDENT_INFO, payload: response.getMessage() })
    }
});
call.on('status', function (status) {
    //console.log(status.details);
});
};
| 归档时间: | 
 | 
| 查看次数: | 717 次 | 
| 最近记录: |