Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
editor_user_id: string;
}>> = mutate(({ state }, { _isOwnMessage, data }) => {
if (!_isOwnMessage) {
const userId = data.editor_user_id;
const editors = state.live.roomInfo.editorIds;
const newEditors = editors.filter(id => id !== userId);
state.live.roomInfo.editorIds = newEditors;
}
});
export const onOperation: Operator> = mutate(({ state, effects }, { _isOwnMessage, data }) => {
if (state.live.isLoading) {
return;
}
if (_isOwnMessage) {
effects.live.serverAck(data.module_shortid);
} else {
try {
effects.live.applyServer(data.module_shortid, data.operation);
} catch (e) {
// Something went wrong, probably a sync mismatch. Request new version
console.error('Something went wrong with applying OT operation');
effects.live.sendModuleStateSyncRequest();
}
}
});
effects.notificationToast.success(
state.live.isTeam ? 'Connected to Live Team!' : 'Connected to Live!'
);
if (state.live.reconnecting) {
effects.live.getAllClients().forEach(client => {
client.serverReconnect();
});
}
state.live.reconnecting = false;
});
export const onModuleState: Operator> = mutate(({ state, actions }, { data }) => {
actions.live.internal.initializeModuleState(data.module_state);
});
export const onUserEntered: Operator> = mutate(({ state, effects }, { data }) => {
if (state.live.isLoading) {
return;
}
const users = camelizeKeys(data.users);
// TODO: What happening here? Is it not an array of users?
state.editor.currentSandbox.modules.splice(moduleIndex, 1);
effects.vscode.sandboxFsSync.unlink(
state.editor.modulesByPath,
removedModule
);
if (wasCurrentModule) {
actions.editor.internal.setCurrentModule(state.editor.mainModule);
}
actions.editor.internal.updatePreviewCode();
});
export const onDirectoryCreated: Operator> = mutate(({ state, effects }, { _isOwnMessage, data }) => {
if (_isOwnMessage) {
return;
}
// Should this not be a directory?
state.editor.currentSandbox.directories.push(data.module);
effects.vscode.sandboxFsSync.mkdir(state.editor.modulesByPath, data.module);
});
export const onDirectoryUpdated: Operator> = mutate(({ state, actions, effects }, { _isOwnMessage, data }) => {
if (_isOwnMessage) {
return;
}
const sandbox = state.editor.currentSandbox;
state.live.reconnecting = false;
});
export const onModuleState: Operator> = mutate(({ state, actions }, { data }) => {
actions.live.internal.initializeModuleState(data.module_state);
});
export const onUserEntered: Operator> = mutate(({ state, effects }, { data }) => {
if (state.live.isLoading) {
return;
}
const users = camelizeKeys(data.users);
// TODO: What happening here? Is it not an array of users?
// Check the running code and fix the type
state.live.roomInfo.users = users as any;
state.live.roomInfo.editorIds = data.editor_ids;
state.live.roomInfo.ownerIds = data.owner_ids;
if (data.joined_user_id === state.live.liveUserId) {
return;
}
if (!state.currentApp.actionQuerySuggestion) {
return
}
state.currentApp.selectedActionQuery = state.currentApp.actionQuerySuggestion
state.currentApp.isQueryingAction = false
state.currentApp.actionQueryPayload = ''
effects.storage.set(
`${state.currentApp.name}.selectedActionQuery`,
state.currentApp.selectedActionQuery
)
}
export const executeAction: Operator = pipe(
mutate(({ state, effects }) => {
state.isExecutingAction = true
const payload = state.currentApp.actionQueryPayload
if (payload && !isValidJson(payload)) {
return
}
effects.connector.sendMessage(state.currentApp.name, 'executeAction', {
name: state.currentApp.selectedActionQuery,
payload: state.currentApp.actionQueryPayload,
})
}),
wait(500),
mutate(({ state, effects }) => {
state.currentApp.actionQueryPayload = ''
mutate(({ state, effects }) => {
state.isExecutingAction = true
const payload = state.currentApp.actionQueryPayload
if (payload && !isValidJson(payload)) {
return
}
effects.connector.sendMessage(state.currentApp.name, 'executeAction', {
name: state.currentApp.selectedActionQuery,
payload: state.currentApp.actionQueryPayload,
})
}),
wait(500),
mutate(({ state, effects }) => {
state.currentApp.actionQueryPayload = ''
effects.storage.set(`${state.currentApp.name}.actionQueryPayload`, '')
state.isExecutingAction = false
})
)
export const setActionQueryPayload: Action = (
{ state, effects },
payload
) => {
state.currentApp.actionQueryPayload = payload
effects.storage.set(`${state.currentApp.name}.actionQueryPayload`, payload)
}
export const setState: Action = ({ state }, path) => {
state.currentApp.selectedStatePath = path.join('.')
const { modules } = state.editor.currentSandbox;
const module = modules.find(m => m.shortid === moduleShortid);
if (!module) {
return;
}
actions.editor.moduleSelected({
id: module.id,
});
}
});
export const onLiveMode: Operator> = mutate(({ state, actions }, { _isOwnMessage, data }) => {
if (!_isOwnMessage) {
state.live.roomInfo.mode = data.mode;
}
actions.live.internal.clearUserSelections(null);
});
export const onLiveChatEnabled: Operator> = mutate(({ state }, { _isOwnMessage, data }) => {
if (_isOwnMessage) {
return;
}
state.live.roomInfo.chatEnabled = data.enabled;
});
export const onLiveAddEditor: Operator
const view = selectionArray[0]
const typescript = String(Boolean(selectionArray[1]))
effects.router.redirectWithQuery(effects.router.getPath(), {
view,
typescript,
})
}
export const closeSearch: Action = ({ state }) => {
state.showSearchResult = false
state.query = ''
}
export const changeQuery: Operator = pipe(
mutate(({ state }, query) => {
state.query = query
state.showSearchResult = query.length > 2
state.isLoadingSearchResult = query.length > 2
}),
filter((_, query) => query.length >= 3),
debounce(200),
mutate(async ({ state, effects }, query) => {
state.searchResult = await effects.request('/backend/search?query=' + query)
state.isLoadingSearchResult = false
})
)
export const viewHelpGotIt: Action = ({ state }) => {
state.showViewHelp = false
}
export const loadHome: () => Operator = () =>
mutate(async function loadHome({ state, effects }) {
state.page = Page.HOME
if (!state.demos.length) {
state.demos = await effects.request('/backend/demos')
}
})
effects.vscode.updateUserSelections([
{
userId: userSelectionLiveUserId,
name: user.username,
selection,
color: json(user.color),
},
]);
}
});
export const onUserCurrentModule: Operator> = mutate(({ state, actions }, { _isOwnMessage, data }) => {
if (_isOwnMessage) {
return;
}
const userIndex = state.live.roomInfo.users.findIndex(
u => u.id === data.live_user_id
);
if (userIndex > -1) {
state.live.roomInfo.users[userIndex].currentModuleShortid =
data.moduleShortid;
}
actions.live.internal.clearUserSelections(null);
if (
state.live.followingUserId === data.live_user_id &&