[CHORE] Remove InteractionManager blocks (#2906)

* [FIX] Remove InteractionManager blocks

* Minor fix

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gung Wah 2021-02-24 02:36:20 +08:00 committed by GitHub
parent 120f50d5d2
commit 3a950547f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 122 additions and 151 deletions

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import lt from 'semver/functions/lt'; import lt from 'semver/functions/lt';
import orderBy from 'lodash/orderBy'; import orderBy from 'lodash/orderBy';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
@ -95,7 +94,6 @@ export function getCustomEmojis() {
// RC 0.61.0 // RC 0.61.0
const result = await this.sdk.get('emoji-custom'); const result = await this.sdk.get('emoji-custom');
InteractionManager.runAfterInteractions(async() => {
let { emojis } = result; let { emojis } = result;
emojis = emojis.filter(emoji => !updatedSince || emoji._updatedAt > updatedSince); emojis = emojis.filter(emoji => !updatedSince || emoji._updatedAt > updatedSince);
const changedEmojis = await updateEmojis({ update: emojis, allRecords }); const changedEmojis = await updateEmojis({ update: emojis, allRecords });
@ -106,7 +104,6 @@ export function getCustomEmojis() {
setCustomEmojis(); setCustomEmojis();
} }
return resolve(); return resolve();
});
} else { } else {
const params = {}; const params = {};
if (updatedSince) { if (updatedSince) {
@ -120,7 +117,6 @@ export function getCustomEmojis() {
return resolve(); return resolve();
} }
InteractionManager.runAfterInteractions(async() => {
const { emojis } = result; const { emojis } = result;
const { update, remove } = emojis; const { update, remove } = emojis;
const changedEmojis = await updateEmojis({ update, remove, allRecords }); const changedEmojis = await updateEmojis({ update, remove, allRecords });
@ -130,7 +126,6 @@ export function getCustomEmojis() {
if (changedEmojis) { if (changedEmojis) {
setCustomEmojis(); setCustomEmojis();
} }
});
} }
} catch (e) { } catch (e) {
log(e); log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import lt from 'semver/functions/lt'; import lt from 'semver/functions/lt';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import orderBy from 'lodash/orderBy'; import orderBy from 'lodash/orderBy';
@ -85,10 +84,8 @@ export default function() {
if (!result.success) { if (!result.success) {
return resolve(); return resolve();
} }
InteractionManager.runAfterInteractions(async() => {
await updatePermissions({ update: result.permissions, allRecords }); await updatePermissions({ update: result.permissions, allRecords });
return resolve(); return resolve();
});
} else { } else {
const params = {}; const params = {};
const updatedSince = await getUpdatedSince(allRecords); const updatedSince = await getUpdatedSince(allRecords);
@ -102,10 +99,8 @@ export default function() {
return resolve(); return resolve();
} }
InteractionManager.runAfterInteractions(async() => {
await updatePermissions({ update: result.update, remove: result.delete, allRecords }); await updatePermissions({ update: result.update, remove: result.delete, allRecords });
return resolve(); return resolve();
});
} }
} catch (e) { } catch (e) {
log(e); log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import database from '../database'; import database from '../database';
@ -19,7 +18,6 @@ export default function() {
const { roles } = result; const { roles } = result;
if (roles && roles.length) { if (roles && roles.length) {
InteractionManager.runAfterInteractions(async() => {
await db.action(async() => { await db.action(async() => {
const rolesCollections = db.collections.get('roles'); const rolesCollections = db.collections.get('roles');
const allRolesRecords = await rolesCollections.query().fetch(); const allRolesRecords = await rolesCollections.query().fetch();
@ -55,7 +53,6 @@ export default function() {
return allRecords.length; return allRecords.length;
}); });
return resolve(); return resolve();
});
} }
} catch (e) { } catch (e) {
log(e); log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import database from '../database'; import database from '../database';
@ -20,7 +19,6 @@ export default function() {
const { commands } = result; const { commands } = result;
if (commands && commands.length) { if (commands && commands.length) {
InteractionManager.runAfterInteractions(async() => {
await db.action(async() => { await db.action(async() => {
const slashCommandsCollection = db.collections.get('slash_commands'); const slashCommandsCollection = db.collections.get('slash_commands');
const allSlashCommandsRecords = await slashCommandsCollection.query().fetch(); const allSlashCommandsRecords = await slashCommandsCollection.query().fetch();
@ -61,7 +59,6 @@ export default function() {
} }
return allRecords.length; return allRecords.length;
}); });
});
} }
} catch (e) { } catch (e) {
log(e); log(e);

View File

@ -1,4 +1,3 @@
import { InteractionManager } from 'react-native';
import { Q } from '@nozbe/watermelondb'; import { Q } from '@nozbe/watermelondb';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
@ -30,7 +29,6 @@ export default function loadThreadMessages({ tmid, rid, offset = 0 }) {
let data = await load.call(this, { tmid, offset }); let data = await load.call(this, { tmid, offset });
if (data && data.length) { if (data && data.length) {
InteractionManager.runAfterInteractions(async() => {
try { try {
data = data.map(m => buildMessage(m)); data = data.map(m => buildMessage(m));
data = await Encryption.decryptMessages(data); data = await Encryption.decryptMessages(data);
@ -67,7 +65,6 @@ export default function loadThreadMessages({ tmid, rid, offset = 0 }) {
log(e); log(e);
} }
return resolve(data); return resolve(data);
});
} else { } else {
return resolve([]); return resolve([]);
} }

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { FlatList, InteractionManager } from 'react-native'; import { FlatList } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Q } from '@nozbe/watermelondb'; import { Q } from '@nozbe/watermelondb';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
@ -73,9 +73,7 @@ class ThreadMessagesView extends React.Component {
componentDidMount() { componentDidMount() {
this.mounted = true; this.mounted = true;
this.mountInteraction = InteractionManager.runAfterInteractions(() => {
this.init(); this.init();
});
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
@ -89,12 +87,6 @@ class ThreadMessagesView extends React.Component {
componentWillUnmount() { componentWillUnmount() {
console.countReset(`${ this.constructor.name }.render calls`); console.countReset(`${ this.constructor.name }.render calls`);
if (this.mountInteraction && this.mountInteraction.cancel) {
this.mountInteraction.cancel();
}
if (this.syncInteraction && this.syncInteraction.cancel) {
this.syncInteraction.cancel();
}
if (this.subSubscription && this.subSubscription.unsubscribe) { if (this.subSubscription && this.subSubscription.unsubscribe) {
this.subSubscription.unsubscribe(); this.subSubscription.unsubscribe();
} }
@ -330,10 +322,8 @@ class ThreadMessagesView extends React.Component {
rid: this.rid, updatedSince: updatedSince.toISOString() rid: this.rid, updatedSince: updatedSince.toISOString()
}); });
if (result.success && result.threads) { if (result.success && result.threads) {
this.syncInteraction = InteractionManager.runAfterInteractions(() => {
const { update, remove } = result.threads; const { update, remove } = result.threads;
this.updateThreads({ update, remove, lastThreadSync: updatedSince }); this.updateThreads({ update, remove, lastThreadSync: updatedSince });
});
} }
this.setState({ this.setState({
loading: false loading: false