Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* relay-muckaround/packages/relay-runtime/store/RelayModernEnvironment.js #sendSubscription
*RelayModernEnvironment#sendSubscription({
onCompleted,
onNext,
onError,
operation,
updater,
}: {
onCompleted?: ?(errors: ?Array) => void,
onNext?: ?(payload: RelayResponsePayload) => void,
onError?: ?(error: Error) => void,
operation: OperationSelector,
updater?: ?SelectorStoreUpdater,
}): Disposable
*/
requestSubscription(environment, {
subscription,
variables: arg,
// after socket has been closed successfully
onCompleted: () => {
alert('done!'); /* need this if payload doesn't contain an id field*/
},
// connection_err ..etc
onError: error => console.error(error),
//end of pipe line; after store merged
onNext: response => {},
// begin of pipe line; before store merged
updater: (
store /*RelayRecordSourceSelectorProxy*/,
data /*selector data, raw json*/
) => {
//@see: relay-muckaround/packages/relay-runtime/store/RelayPublishQueue.js
const subscribe = ({
environment,
subscriptionOptions,
}: {|
environment: Object,
subscriptionOptions: Object,
|}) => {
requestSubscription(environment, {
...subscriptionOptions,
// onNext: data => {
// console.log('RX at END-USER-LEVEL:', data);
// },
});
};
function subscribeToCreates(env, viewer) {
return requestSubscription(env,
{
subscription: createSubscription,
variables: {user: viewer.id},
onCompleted: () => console.log('Create subscription closed.'),
onError: err => console.error('Error subscribing to todo updates:', err),
onNext: resp => console.log('Create event:', resp),
updater: makeUpdater(viewer, 'createdTodo')
});
}
export default ({ environment, subscription, updaters = [], variables }) => {
let _updaters = updaters
requestSubscription(environment, {
subscription,
variables,
onNext: () => {},
onCompleted: () => {},
onError: error => console.error(error),
updater: (store, data) =>
_updaters.forEach(updater => updater(store, data)),
})
return {
subscribe: ({ updater }) => {
updater && _updaters.push(updater)
return {
unsubscribe: () => {
_updaters = updater ? _updaters.filter(_ => _ !== updater) : _updaters
},
function subscribeToDeletes(env, viewer) {
return requestSubscription(env,
{
subscription: deleteSubscription,
variables: {user: viewer.id},
onCompleted: () => console.log('Delete subscription closed.'),
onError: err => console.error('Error subscribing to todo deletes:', err),
onNext: resp => console.log('Delete event:', resp),
configs: [{
type: 'RANGE_DELETE',
parentID: viewer.id,
connectionKeys: [{key: 'TodoList_listTodos'}],
pathToConnection: ['viewer', 'edges'],
deletedIDFieldName: 'deletedId',
}]
});
}
const tweetsConnection = ConnectionHandler.getConnection(
root,
"Feed_tweets"
);
const tweetEdge = ConnectionHandler.createEdge(
store,
tweetsConnection!,
tweet!,
"TweetsEdge"
);
ConnectionHandler.insertEdgeBefore(tweetsConnection!, tweetEdge!);
}
};
requestSubscription(Environment, subscriptionConfig);
};
componentDidMount() {
if (isBuildFinalStatus(this.props.build.status)) {
return;
}
let variables = { buildID: this.props.build.id };
this.subscription = requestSubscription(environment, {
subscription: buildSubscription,
variables: variables,
});
}
export const requestSubscription = args => (WS_ACTIVATED ? RS(environment, args) : deactivateSubscription);
componentDidMount() {
if (isTaskFinalStatus(this.props.task.status)) {
return;
}
let variables = { taskID: this.props.task.id };
this.subscription = requestSubscription(environment, {
subscription: taskSubscription,
variables: variables,
});
}
export const requestSubscription = (args) => (WS_ACTIVATED ? RS(environment, args) : deactivateSubscription);