我在我的项目中使用 graphql 订阅,它是一个 Instagram 克隆,我正在做喜欢或不喜欢帖子的功能,我用它npx create-react-app来创建我的客户端,我用它express来制作我的服务器。
client在客户端,我这样设置:
src/apis/client.js
import {
ApolloClient,
ApolloLink,
HttpLink,
InMemoryCache,
split,
} from 'apollo-boost';
import {getMainDefinition} from '@apollo/client/utilities';
import {WebSocketLink} from '@apollo/client/link/ws';
const httpUrl = 'http://localhost:5000/graphql';
const wsUrl = 'ws://localhost:5000/graphql';
const httpLink = ApolloLink.from([
new ApolloLink((operation, forward) => {}),
new HttpLink({uri: httpUrl}),
]);
const wsLink = new WebSocketLink({
uri: wsUrl,
options: {
// connectionParams: () => {},
lazy: true,
reconnect: true,
},
});
function isSubscription(operation) {
const definition = getMainDefinition(operation.query);
return …Run Code Online (Sandbox Code Playgroud) 我正在将 Redux 和 Redux Saga 用于我的在线购物网站项目,所以这就是我所做的:
actions/products.js
export const Types = {
GET_PRODUCTS_REQUEST: 'products/get_products_request',
GET_PRODUCTS_SUCCESS: 'products/get_products_success',
CREATE_PRODUCT_REQUEST: 'products/create_product_request',
};
export const getProductRequest = () => ({
type: Types.GET_PRODUCTS_REQUEST,
});
export const getProductSuccess = ({products}) => ({
type: Types.GET_PRODUCTS_SUCCESS,
payload: {
products,
},
});
export const createProductRequest = ({
name,
price,
description,
productImage,
}) => ({
type: Types.CREATE_PRODUCT_REQUEST,
payload: {
name,
price,
description,
productImage,
},
});
Run Code Online (Sandbox Code Playgroud)
reducers/products.js
import {Types} from '../actions/products';
const INTIAL_STATE = {
products: [],
error: '',
};
export …Run Code Online (Sandbox Code Playgroud) 我正在使用 Firebase 托管来部署我的应用程序
如您所见,我有 2 个应用程序:clone-a50db并且clone-eeb88该应用程序clone-eeb88已在使用中,所以现在我想将我的应用程序部署到另一个应用程序,即clone-a50db.
我就是这样做的:
firebase init
? Are you ready to proceed? Yes
? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. Hosting: Configure and deploy Firebase Hosting sites`
=== Project Setup
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add, …Run Code Online (Sandbox Code Playgroud) javascript ×3
web ×3
reactjs ×2
express ×1
firebase ×1
graphql ×1
redux ×1
redux-saga ×1
websocket ×1