不同的背景色调在一个vim窗口中(Different background shades in a single vim window)
例如,在一个带有4个或5个缓冲区的VIM窗口中,是否可以为每个缓冲区提供不同的背景阴影?
让我们假设颜色主题是深蓝色,我想让每个缓冲区的深蓝色背景色略有不同。
In a single VIM window with 4 or 5 buffers for example, is it possible to give each buffer a different background shade?
Let's assume that the color theme is darkblue, I would like to make each buffer have a slightly different background shade of the dark blue.
原文:https://stackoverflow.com/questions/8386438
最满意答案
每当Apollo HOC收到新的道具时,它会导致你的行动开始,这会更新商店并将新的道具发送到你的Apollo HOC,这会导致你的行动开始......
有几种不同的方法可以处理这个问题。 在我看来,最直接的方法就是删除
graphql
HOC,然后使用withApollo
。 就像是:compose( withApollo, connect(mapStateToProps, mapDispatchToProps) lifecycle({ componentDidMount() { const { client } = this.props client.query({ query: AllRefreshTokens }) .then(({data}) => { receivedAdminTokens(data.allUsers) }) .catch( //any error handling logic ) } }) )
以上使用重构的
lifecycle
但您可以轻松地将componentDidMount
方法粘贴到组件中。也就是说,在Apollo已经为你做的时候,使用Redux来存储你的GraphQL查询的结果似乎有点多余。
Apollo的默认行为是首先从缓存中检索数据,并且只在数据不存在的情况下发出网络请求(这也是您只看到一次网络调用的原因)。 这意味着应用程序内部的任何组件都可以用相同的
graphql
HOCgraphql
,只有第一个要呈现的组件才会触发对您的GraphQL端点的请求 - 所有其他组件都会从缓存中获取它们的data
。Whenever the Apollo HOC receives new props, it causes your action to fire, which updates the store and sends new props to your Apollo HOC, which causes your action to fire...
There's a couple of different ways you could handle this. In my mind, the most straightforward would be to drop the
graphql
HOC and usewithApollo
instead. Something like:compose( withApollo, connect(mapStateToProps, mapDispatchToProps) lifecycle({ componentDidMount() { const { client } = this.props client.query({ query: AllRefreshTokens }) .then(({data}) => { receivedAdminTokens(data.allUsers) }) .catch( //any error handling logic ) } }) )
The above uses recompose's
lifecycle
but you could just as easily stick thecomponentDidMount
method inside your component.That said, it seems a little redundant to use Redux to store the results of your GraphQL queries when Apollo already does it for you.
Apollo's default behavior is to retrieve the data from the cache first, and only make a network request if the data doesn't exist (which is also why you only saw the one network call). That means any number of components inside your app could be wrapped with the same
graphql
HOC, and only the first component to be rendered would trigger a request to your GraphQL endpoint -- all other components would get theirdata
from the cache.
相关问答
更多-
您需要将curData转换为Apollo graphql格式并使用它来初始化商店的Apollo部分。 你可以在这里阅读具体内容: http : //dev.apollodata.com/react/server-side-rendering.html#store-rehydration 请注意,Apollo实际上支持服务器端呈现,因此如果您在服务器上使用Apollo Graphql,它实际上会生成您需要发送到客户端以用于初始化客户端Redux存储的状态 You need to transform the c ...
-
Redux设置|(Redux Setup | ReactJS | ES6)[2024-01-20]
在Reducers/index.js ,将其更改为export default store; ,您正在导出reducers对象,然后您尝试将其作为Client.js的函数运行。 Within Reducers/index.js, change it to export default store;, you are exporting the reducers object, which you then attempt to run as a function in Client.js. -
Apollo 2.x客户端和服务器设置:WebSocket握手期间出错?(Apollo 2.x Client and Server Setup: Error during WebSocket handshake?)[2023-06-12]
首先想到的是: 您的服务器侦听端口3200并使用路由graphql 。 const subscriptionServer = SubscriptionServer.create( { schema, execute, subscribe, }, { server: websocketServer, path: '/graphql', // used url route }, ) ... -
Apollo Client和Redux设置会导致无限的渲染循环(Apollo Client and Redux setup causes infinite render loop)[2021-08-20]
每当Apollo HOC收到新的道具时,它会导致你的行动开始,这会更新商店并将新的道具发送到你的Apollo HOC,这会导致你的行动开始...... 有几种不同的方法可以处理这个问题。 在我看来,最直接的方法就是删除graphql HOC,然后使用withApollo 。 就像是: compose( withApollo, connect(mapStateToProps, mapDispatchToProps) lifecycle({ componentDidMount() { ... -
您正在使用'apollo-boost'中的ApolloClient,但您的令牌配置用于另一个ApolloClient,即来自'apollo-client'的{ApolloClient}。 如果您想使用Apollo-boost中的ApolloClient保存令牌: const client = new ApolloClient({ uri: ..., request: async operation => { const token = await localStorage.getItem(' ...
-
我需要在我的actions.js中使用ApolloClient。 例如 import ApolloClient, { createNetworkInterface } from 'apollo-client'; const networkInterface = createNetworkInterface({ uri: config.graphCoolUri, }); const client = new ApolloClient({ networkInterface, dataIdFromO ...
-
编辑:问题的海报用这段代码解决了他自己的问题: shouldComponentUpdate(nextProps) { if (nextProps.data.loading === false) { return true; } else { return false; } } 我认为您正在使用shouldComponentUpdate思考正确的方向,但不是检查加载状态是否不同,而是检查您的数据是否不同。 shouldComponentUpdate (nextProps) { ...
-
您想要执行类似于Redux示例站点的操作 https://github.com/gatsbyjs/gatsby/blob/master/examples/using-redux/gatsby-browser.js 在使用来自Graph.cool的数据之前,您需要注意的一件事就是始终检查您是否在客户端。 如果您正在使用静态渲染的组件,则不能指望graph.cool数据可用,因为组件将在服务器和客户端上呈现。 You want to do something similar to the Redux examp ...
-
如何在React Native中正确地将Apollo Client连接到Redux(How to properly hook up Apollo Client to Redux in React Native)[2023-10-22]
当您使用compose ,您的HOC的顺序很重要。 在您的代码中,您的第一个HOC( connect )添加的道具可供其后的所有HOC使用( withFormik和graphql )。 withFormik添加的道具仅适用于graphql 。 graphql添加的道具既不适用于其他两个HOC(只是组件本身)。 如果您重新排列要compose的顺序 - > graphql - > withFormik那么您应该可以访问props.mutate中的withFormik 。 此外,虽然您可以集成Redux和Apo ... -
我应该直接使用Apollo数据还是在Redux商店中保存/修改它?(Should I work directly with Apollo data or save/modify it in Redux store?)[2024-04-15]
你读过关于更新缓存的文档吗? 发送编辑任何内容的突变时,通常会将修改后的对象作为响应。 当收到更新的对象时, react-apollo自动更新相应的本地存储的对象,该对象与接收到的相同的id和__typename相对应。 因此,如果在组件上使用graphql装饰器从Apollo商店注入道具,当商店因突变或查询而更新时,应该再次自动传递道具。 无需手动修改它们。 在某些情况下,您需要使用store.readyQuery和store.writeQuery ,但它们是边缘案例,希望不会太多。 尽管如此,除非你感到 ...