Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const relayContext = assertRelayContext(nextProps.__relayContext)
const prevIDs = getDataIDsFromObject(fragments, prevProps)
const nextIDs = getDataIDsFromObject(fragments, nextProps)
let resolver = prevState.resolver
// If the environment has changed or props point to new records then
// previously fetched data and any pending fetches no longer apply:
// - Existing references are on the old environment.
// - Existing references are based on old variables.
// - Pending fetches are for the previous records.
if (
prevState.prevPropsContext.environment !== relayContext.environment ||
prevState.prevPropsContext.variables !== relayContext.variables ||
!areEqual(prevIDs, nextIDs)
) {
// Do not provide a subscription/callback here.
// It is possible for this render to be interrupted or aborted,
// In which case the subscription would cause a leak.
// We will add the subscription in componentDidUpdate().
resolver = createFragmentSpecResolver(
relayContext,
containerName,
fragments,
nextProps
)
return {
data: resolver.resolve(),
localVariables: null,
prevProps: nextProps,
prevPropsContext: relayContext,
case 'assert': {
const [type, _, other] = args; // eslint-disable-line no-unused-vars
if (type === 'no_error') {
assert(
!nullthrows(subscriber).hasError(),
'Expected onError not to be called.',
);
} else if (type === 'error') {
assert(
nullthrows(subscriber).hasError(),
'Expected onError to be called.',
);
} else if (type === 'received') {
const expected = parsePayloads(other);
const actual = nullthrows(subscriber).getPayloads();
if (!areEqual(actual, expected)) {
log('expected: %s', util.inspect(expected));
log('actual: %s', util.inspect(actual));
assert(false, 'Actual/expected payloads differed.');
}
} else if (type === 'received_n') {
const expected = parseInt(other, 10);
const actual = nullthrows(subscriber).getPayloads().length;
assert(
actual === expected,
'Expected exactly %s payloads, got %s.',
expected,
actual,
);
} else if (type === 'received_at_least') {
const expected = parseInt(other, 10);
const actual = nullthrows(subscriber).getPayloads().length;
const { prevProps } = prevState
const relayContext = assertRelayContext(nextProps.__relayContext)
const prevIDs = getDataIDsFromObject(fragments, prevProps)
const nextIDs = getDataIDsFromObject(fragments, nextProps)
let resolver = prevState.resolver
// If the environment has changed or props point to new records then
// previously fetched data and any pending fetches no longer apply:
// - Existing references are on the old environment.
// - Existing references are based on old variables.
// - Pending fetches are for the previous records.
if (
prevState.prevPropsContext.environment !== relayContext.environment ||
prevState.prevPropsContext.variables !== relayContext.variables ||
!areEqual(prevIDs, nextIDs)
) {
// Do not provide a subscription/callback here.
// It is possible for this render to be interrupted or aborted,
// In which case the subscription would cause a leak.
// We will add the subscription in componentDidUpdate().
resolver = createFragmentSpecResolver(
relayContext,
containerName,
fragments,
nextProps
)
return {
data: resolver.resolve(),
prevPropsContext: relayContext,
prevProps: nextProps,
// Any props change could impact the query, so we mirror props in state.
// This is an unusual pattern, but necessary for this container usecase.
const { prevProps } = prevState
const relayContext = assertRelayContext(nextProps.__relayContext)
const prevIDs = getDataIDsFromObject(fragments, prevProps)
const nextIDs = getDataIDsFromObject(fragments, nextProps)
// If the environment has changed or props point to new records then
// previously fetched data and any pending fetches no longer apply:
// - Existing references are on the old environment.
// - Existing references are based on old variables.
// - Pending fetches are for the previous records.
if (
prevState.prevPropsContext.environment !== relayContext.environment ||
prevState.prevPropsContext.variables !== relayContext.variables ||
!areEqual(prevIDs, nextIDs)
) {
this._cleanup()
// Child containers rely on context.relay being mutated (for gDSFP).
this._resolver = createFragmentSpecResolver(
relayContext,
containerName,
fragments,
nextProps,
this._handleFragmentDataUpdate
)
return {
data: this._resolver.resolve(),
prevProps: nextProps,
prevPropsContext: relayContext,
contextForChildren: relayContext,
relayProp: this._buildRelayProp(relayContext)
var prevData = _this._resolver.resolve();
_this._resolver.setVariables(getFragmentVariables(fragmentVariables, paginatingVariables.totalCount), operation.node);
var nextData = _this._resolver.resolve(); // Workaround slightly different handling for connection in different
// core implementations:
// - Classic core requires the count to be explicitly incremented
// - Modern core automatically appends new items, updating the count
// isn't required to see new data.
//
// `setState` is only required if changing the variables would change the
// resolved data.
// TODO #14894725: remove PaginationContainer equal check
if (!areEqual(prevData, nextData)) {
_this.setState({
data: nextData,
contextForChildren: {
environment: _this.props.__relayContext.environment,
variables: contextVariables
}
}, complete);
} else {
complete();
}
};
paginatingVariables.totalCount
),
operation.node
)
const nextData = this._resolver.resolve()
// Workaround slightly different handling for connection in different
// core implementations:
// - Classic core requires the count to be explicitly incremented
// - Modern core automatically appends new items, updating the count
// isn't required to see new data.
//
// `setState` is only required if changing the variables would change the
// resolved data.
// TODO #14894725: remove PaginationContainer equal check
if (!areEqual(prevData, nextData)) {
this.setState(
{
data: nextData,
contextForChildren: {
environment: this.props.__relayContext.environment,
variables: contextVariables
}
},
complete
)
} else {
complete()
}
}
shouldComponentUpdate(nextProps, nextState) {
return !areEqual(this.state, nextState) || !areEqual(this.props, nextProps);
}
export function createOrReusePropsNode(props, callback, oldNode) {
if (props.style) {
props = {
...props,
style: createOrReuseStyleNode(
props.style,
oldNode && oldNode._props.style
),
};
}
const config = sanitizeProps(props);
if (oldNode && deepEqual(config, oldNode._config)) {
return oldNode;
}
return new AnimatedProps(props, config, callback);
}
_update() {
const newConfig = filterConfig(
transformProps ? transformProps(this.props) : this.props,
{ ...this.constructor.propTypes, ...customNativeProps },
config
);
if (!deepEqual(this._config, newConfig)) {
this._updateGestureHandler(newConfig);
}
}