Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit288aebd

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Make store an optional argument when constructing a Relay Environment
Reviewed By: lynnshaoyuDifferential Revision: D73151474fbshipit-source-id: d548f75298d34e20fc598ec0f64f8ed4d2cf6c70
1 parent63c8437 commit288aebd

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

‎packages/relay-runtime/store/RelayModernEnvironment.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const defaultGetDataID = require('./defaultGetDataID');
5858
constdefaultRelayFieldLogger=require('./defaultRelayFieldLogger');
5959
constnormalizeResponse=require('./normalizeResponse');
6060
constOperationExecutor=require('./OperationExecutor');
61+
constRelayModernStore=require('./RelayModernStore');
6162
constRelayPublishQueue=require('./RelayPublishQueue');
6263
constRelayRecordSource=require('./RelayRecordSource');
6364
constinvariant=require('invariant');
@@ -71,7 +72,7 @@ export type EnvironmentConfig = {
7172
+network:INetwork,
7273
+normalizeResponse?: ?NormalizeResponseFunction,
7374
+scheduler?: ?TaskScheduler,
74-
+store:Store,
75+
+store?:Store,
7576
+missingFieldHandlers?: ?$ReadOnlyArray<MissingFieldHandler>,
7677
+operationTracker?: ?OperationTracker,
7778
+getDataID?: ?GetDataID,
@@ -118,6 +119,15 @@ class RelayModernEnvironment implements IEnvironment {
118119
);
119120
}
120121
}
122+
conststore=
123+
config.store??
124+
newRelayModernStore(newRelayRecordSource(),{
125+
log:config.log,
126+
operationLoader:config.operationLoader,
127+
getDataID:config.getDataID,
128+
shouldProcessClientComponents:config.shouldProcessClientComponents,
129+
});
130+
121131
this.__log=config.log??emptyFunction;
122132
this.relayFieldLogger=config.relayFieldLogger??defaultRelayFieldLogger;
123133
this._defaultRenderPolicy=
@@ -128,14 +138,14 @@ class RelayModernEnvironment implements IEnvironment {
128138
this._getDataID=config.getDataID??defaultGetDataID;
129139
this._missingFieldHandlers=config.missingFieldHandlers??[];
130140
this._publishQueue=newRelayPublishQueue(
131-
config.store,
141+
store,
132142
config.handlerProvider??RelayDefaultHandlerProvider,
133143
this._getDataID,
134144
this._missingFieldHandlers,
135145
this.__log,
136146
);
137147
this._scheduler=config.scheduler??null;
138-
this._store=config.store;
148+
this._store=store;
139149
this.options=config.options;
140150
this._isServer=config.isServer??false;
141151
this._normalizeResponse=config.normalizeResponse??normalizeResponse;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*@flow strict-local
8+
*@format
9+
*@oncall relay
10+
*/
11+
12+
constRelayNetwork=require('../../network/RelayNetwork');
13+
constRelayModernEnvironment=require('../RelayModernEnvironment');
14+
constRelayModernStore=require('../RelayModernStore');
15+
16+
describe('new Environment()',()=>{
17+
it('creates a properly configured Relay Store if one is not provided',()=>{
18+
constlog=()=>{};
19+
constoperationLoader={
20+
get:jest.fn(),
21+
load:jest.fn(),
22+
};
23+
constgetDataID=()=>'lol';
24+
constshouldProcessClientComponents=true;
25+
constnetwork=RelayNetwork.create(jest.fn());
26+
constenvironment=newRelayModernEnvironment({
27+
network,
28+
log,
29+
operationLoader,
30+
getDataID,
31+
shouldProcessClientComponents,
32+
});
33+
34+
conststore=environment.getStore();
35+
36+
if(!(storeinstanceofRelayModernStore)){
37+
thrownewError('Expected store to be an instance of RelayModernStore');
38+
}
39+
expect(store.__log).toBe(log);
40+
});
41+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp