diff options
| author | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2018-12-11 20:36:55 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-11 20:36:55 +0900 |
| commit | 125849673a1aba46021852ee473d00f4520d1bd6 (patch) | |
| tree | e30d39490236df402b97a9963dafa44eaf549368 /src/client/app/common | |
| parent | Fix error (diff) | |
| download | misskey-125849673a1aba46021852ee473d00f4520d1bd6.tar.gz misskey-125849673a1aba46021852ee473d00f4520d1bd6.tar.bz2 misskey-125849673a1aba46021852ee473d00f4520d1bd6.zip | |
Use for-of instead of forEach (#3583)
Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
Diffstat (limited to 'src/client/app/common')
12 files changed, 46 insertions, 46 deletions
diff --git a/src/client/app/common/define-widget.ts b/src/client/app/common/define-widget.ts index 56314a4104..5eb9718446 100644 --- a/src/client/app/common/define-widget.ts +++ b/src/client/app/common/define-widget.ts @@ -1,6 +1,6 @@ import Vue from 'vue'; -export default function<T extends object>(data: { +export default function <T extends object>(data: { name: string; props?: () => T; }) { @@ -53,11 +53,10 @@ export default function<T extends object>(data: { mergeProps() { if (data.props) { const defaultProps = data.props(); - Object.keys(defaultProps).forEach(prop => { - if (!this.props.hasOwnProperty(prop)) { - Vue.set(this.props, prop, defaultProps[prop]); - } - }); + for (const prop of Object.keys(defaultProps)) { + if (this.props.hasOwnProperty(prop)) continue; + Vue.set(this.props, prop, defaultProps[prop]); + } } }, diff --git a/src/client/app/common/hotkey.ts b/src/client/app/common/hotkey.ts index 28a5ec204d..b2afd57ae3 100644 --- a/src/client/app/common/hotkey.ts +++ b/src/client/app/common/hotkey.ts @@ -28,15 +28,15 @@ const getKeyMap = keymap => Object.entries(keymap).map(([patterns, callback]): a shift: false } as pattern; - part.trim().split('+').forEach(key => { - key = key.trim().toLowerCase(); + const keys = part.trim().split('+').map(x => x.trim().toLowerCase()); + for (const key of keys) { switch (key) { case 'ctrl': pattern.ctrl = true; break; case 'alt': pattern.alt = true; break; case 'shift': pattern.shift = true; break; default: pattern.which = keyCode(key).map(k => k.toLowerCase()); } - }); + } return pattern; }); diff --git a/src/client/app/common/scripts/check-for-update.ts b/src/client/app/common/scripts/check-for-update.ts index e8a5d18f09..20da83a0c2 100644 --- a/src/client/app/common/scripts/check-for-update.ts +++ b/src/client/app/common/scripts/check-for-update.ts @@ -14,9 +14,10 @@ export default async function($root: any, force = false, silent = false) { navigator.serviceWorker.controller.postMessage('clear'); } - navigator.serviceWorker.getRegistrations().then(registrations => { - registrations.forEach(registration => registration.unregister()); - }); + const registrations = await navigator.serviceWorker.getRegistrations(); + for (const registration of registrations) { + registration.unregister(); + } } catch (e) { console.error(e); } diff --git a/src/client/app/common/scripts/stream.ts b/src/client/app/common/scripts/stream.ts index 80278a76f6..23f839ae85 100644 --- a/src/client/app/common/scripts/stream.ts +++ b/src/client/app/common/scripts/stream.ts @@ -111,9 +111,9 @@ export default class Stream extends EventEmitter { connections = [this.nonSharedConnections.find(c => c.id === id)]; } - connections.filter(c => c != null).forEach(c => { + for (const c of connections.filter(c => c != null)) { c.emit(body.type, body.body); - }); + } } else { this.emit(type, body); } diff --git a/src/client/app/common/views/components/autocomplete.vue b/src/client/app/common/views/components/autocomplete.vue index 1d860ff545..e33e4ae8c5 100644 --- a/src/client/app/common/views/components/autocomplete.vue +++ b/src/client/app/common/views/components/autocomplete.vue @@ -57,18 +57,18 @@ const emjdb: EmojiDef[] = lib.map((x: any) => ({ url: `https://twemoji.maxcdn.com/2/svg/${char2file(x[1].char)}.svg` })); -lib.forEach((x: any) => { +for (const x of lib as any) { if (x[1].keywords) { - x[1].keywords.forEach(k => { + for (const k of x[1].keywords) { emjdb.push({ emoji: x[1].char, name: k, aliasOf: x[0], url: `https://twemoji.maxcdn.com/2/svg/${char2file(x[1].char)}.svg` }); - }); + } } -}); +} emjdb.sort((a, b) => a.name.length - b.name.length); @@ -120,7 +120,7 @@ export default Vue.extend({ const customEmojis = (this.$root.getMetaSync() || { emojis: [] }).emojis || []; const emojiDefinitions: EmojiDef[] = []; - customEmojis.forEach(x => { + for (const x of customEmojis) { emojiDefinitions.push({ name: x.name, emoji: `:${x.name}:`, @@ -129,7 +129,7 @@ export default Vue.extend({ }); if (x.aliases) { - x.aliases.forEach(alias => { + for (const alias of x.aliases) { emojiDefinitions.push({ name: alias, aliasOf: x.name, @@ -137,9 +137,9 @@ export default Vue.extend({ url: x.url, isCustomEmoji: true }); - }); + } } - }); + } emojiDefinitions.sort((a, b) => a.name.length - b.name.length); @@ -148,9 +148,9 @@ export default Vue.extend({ this.textarea.addEventListener('keydown', this.onKeydown); - Array.from(document.querySelectorAll('body *')).forEach(el => { + for (const el of Array.from(document.querySelectorAll('body *'))) { el.addEventListener('mousedown', this.onMousedown); - }); + } this.$nextTick(() => { this.exec(); @@ -166,18 +166,18 @@ export default Vue.extend({ beforeDestroy() { this.textarea.removeEventListener('keydown', this.onKeydown); - Array.from(document.querySelectorAll('body *')).forEach(el => { + for (const el of Array.from(document.querySelectorAll('body *'))) { el.removeEventListener('mousedown', this.onMousedown); - }); + } }, methods: { exec() { this.select = -1; if (this.$refs.suggests) { - Array.from(this.items).forEach(el => { + for (const el of Array.from(this.items)) { el.removeAttribute('data-selected'); - }); + } } if (this.type == 'user') { @@ -316,9 +316,9 @@ export default Vue.extend({ }, applySelect() { - Array.from(this.items).forEach(el => { + for (const el of Array.from(this.items)) { el.removeAttribute('data-selected'); - }); + } this.items[this.select].setAttribute('data-selected', 'true'); (this.items[this.select] as any).focus(); diff --git a/src/client/app/common/views/components/emoji-picker.vue b/src/client/app/common/views/components/emoji-picker.vue index 8181047167..f9164ad524 100644 --- a/src/client/app/common/views/components/emoji-picker.vue +++ b/src/client/app/common/views/components/emoji-picker.vue @@ -114,11 +114,11 @@ export default Vue.extend({ }, onScroll(e) { - const section = this.categories.forEach(x => { + for (const x of this.categories) { const top = e.target.scrollTop; const el = this.$refs[x.ref][0]; x.isActive = el.offsetTop <= top && el.offsetTop + el.offsetHeight > top; - }); + } }, chosen(emoji) { diff --git a/src/client/app/common/views/components/games/reversi/reversi.game.vue b/src/client/app/common/views/components/games/reversi/reversi.game.vue index c5619f9058..6d13b34c32 100644 --- a/src/client/app/common/views/components/games/reversi/reversi.game.vue +++ b/src/client/app/common/views/components/games/reversi/reversi.game.vue @@ -185,9 +185,9 @@ export default Vue.extend({ loopedBoard: this.game.settings.loopedBoard }); - this.game.logs.forEach(log => { + for (const log of this.game.logs) { this.o.put(log.color, log.pos); - }); + } this.logs = this.game.logs; this.logPos = this.logs.length; @@ -287,9 +287,9 @@ export default Vue.extend({ loopedBoard: this.game.settings.loopedBoard }); - this.game.logs.forEach(log => { + for (const log of this.game.logs) { this.o.put(log.color, log.pos, true); - }); + } this.logs = this.game.logs; this.logPos = this.logs.length; diff --git a/src/client/app/common/views/components/messaging-room.vue b/src/client/app/common/views/components/messaging-room.vue index b6132ceeb0..29aacd3bae 100644 --- a/src/client/app/common/views/components/messaging-room.vue +++ b/src/client/app/common/views/components/messaging-room.vue @@ -196,12 +196,12 @@ export default Vue.extend({ onRead(ids) { if (!Array.isArray(ids)) ids = [ids]; - ids.forEach(id => { + for (const id of ids) { if (this.messages.some(x => x.id == id)) { const exist = this.messages.map(x => x.id).indexOf(id); this.messages[exist].isRead = true; } - }); + } }, isBottom() { @@ -248,13 +248,13 @@ export default Vue.extend({ onVisibilitychange() { if (document.hidden) return; - this.messages.forEach(message => { + for (const message of this.messages) { if (message.userId !== this.$store.state.i.id && !message.isRead) { this.connection.send('read', { id: message.id }); } - }); + } } } }); diff --git a/src/client/app/common/views/components/messaging.vue b/src/client/app/common/views/components/messaging.vue index f8d0623b99..9683ca0ca3 100644 --- a/src/client/app/common/views/components/messaging.vue +++ b/src/client/app/common/views/components/messaging.vue @@ -103,10 +103,10 @@ export default Vue.extend({ this.messages.unshift(message); }, onRead(ids) { - ids.forEach(id => { + for (const id of ids) { const found = this.messages.find(m => m.id == id); if (found) found.isRead = true; - }); + } }, search() { if (this.q == '') { diff --git a/src/client/app/common/views/components/poll.vue b/src/client/app/common/views/components/poll.vue index 8a31ec83d7..8817d88cc5 100644 --- a/src/client/app/common/views/components/poll.vue +++ b/src/client/app/common/views/components/poll.vue @@ -55,12 +55,12 @@ export default Vue.extend({ noteId: this.note.id, choice: id }).then(() => { - this.poll.choices.forEach(c => { + for (const c of this.poll.choices) { if (c.id == id) { c.votes++; Vue.set(c, 'isVoted', true); } - }); + } this.showResult = true; }); } diff --git a/src/client/app/common/views/widgets/posts-monitor.vue b/src/client/app/common/views/widgets/posts-monitor.vue index 9b2cc5a6cd..1af306b881 100644 --- a/src/client/app/common/views/widgets/posts-monitor.vue +++ b/src/client/app/common/views/widgets/posts-monitor.vue @@ -164,7 +164,7 @@ export default define({ this.draw(); }, onStatsLog(statsLog) { - statsLog.forEach(stats => this.onStats(stats)); + for (const stats of statsLog) this.onStats(stats); } } }); diff --git a/src/client/app/common/views/widgets/server.cpu-memory.vue b/src/client/app/common/views/widgets/server.cpu-memory.vue index 4a0341ddcd..92e5479b1b 100644 --- a/src/client/app/common/views/widgets/server.cpu-memory.vue +++ b/src/client/app/common/views/widgets/server.cpu-memory.vue @@ -121,7 +121,7 @@ export default Vue.extend({ this.memP = (stats.mem.used / stats.mem.total * 100).toFixed(0); }, onStatsLog(statsLog) { - statsLog.reverse().forEach(stats => this.onStats(stats)); + for (const stats of statsLog.reverse()) this.onStats(stats); } } }); |