client: replace array concat with Array.prototype.flat

This commit is contained in:
Johann150 2023-02-04 00:21:13 +01:00
parent 85a68a5eee
commit 63665e8bd1
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 5 additions and 14 deletions

View file

@ -9,7 +9,6 @@
import { computed } from 'vue'; import { computed } from 'vue';
import { length } from 'stringz'; import { length } from 'stringz';
import * as foundkey from 'foundkey-js'; import * as foundkey from 'foundkey-js';
import { concat } from '@/scripts/array';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
const props = defineProps<{ const props = defineProps<{
@ -22,12 +21,12 @@ const emit = defineEmits<{
}>(); }>();
const label = computed(() => { const label = computed(() => {
return concat([ return [
props.note.text ? [i18n.t('_cw.chars', { count: length(props.note.text) })] : [], props.note.text ? [i18n.t('_cw.chars', { count: length(props.note.text) })] : [],
props.note.files && props.note.files.length !== 0 ? [i18n.t('_cw.files', { count: props.note.files.length }) ] : [], props.note.files && props.note.files.length !== 0 ? [i18n.t('_cw.files', { count: props.note.files.length }) ] : [],
props.note.poll != null ? [i18n.ts.poll] : [], props.note.poll != null ? [i18n.ts.poll] : [],
props.note.renoteId != null ? [i18n.ts.quote] : [], props.note.renoteId != null ? [i18n.ts.quote] : [],
] as string[][]).join(' / '); ].flat().join(' / ');
}); });
const toggle = () => { const toggle = () => {

View file

@ -4,7 +4,6 @@ import MkUrl from '@/components/global/url.vue';
import MkLink from '@/components/link.vue'; import MkLink from '@/components/link.vue';
import MkMention from '@/components/mention.vue'; import MkMention from '@/components/mention.vue';
import MkEmoji from '@/components/global/emoji.vue'; import MkEmoji from '@/components/global/emoji.vue';
import { concat } from '@/scripts/array';
import MkFormula from '@/components/formula.vue'; import MkFormula from '@/components/formula.vue';
import MkCode from '@/components/code.vue'; import MkCode from '@/components/code.vue';
import MkSearch from '@/components/mfm-search.vue'; import MkSearch from '@/components/mfm-search.vue';
@ -50,7 +49,7 @@ export default defineComponent({
return t.match(/^[0-9.]+s$/) ? t : null; return t.match(/^[0-9.]+s$/) ? t : null;
}; };
const genEl = (ast: mfm.MfmNode[]) => concat(ast.map((token): VNode[] => { const genEl = (ast: mfm.MfmNode[]) => ast.map((token): VNode[] => {
switch (token.type) { switch (token.type) {
case 'text': { case 'text': {
const text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n'); const text = token.props.text.replace(/(\r\n|\n|\r)/g, '\n');
@ -314,7 +313,7 @@ export default defineComponent({
return []; return [];
} }
} }
})); }).flat();
// Parse ast to DOM // Parse ast to DOM
return h('span', genEl(ast)); return h('span', genEl(ast));

View file

@ -15,19 +15,12 @@ export function count<T>(a: T, xs: T[]): number {
return countIf(x => x === a, xs); return countIf(x => x === a, xs);
} }
/**
* Concatenate an array of arrays
*/
export function concat<T>(xss: T[][]): T[] {
return ([] as T[]).concat(...xss);
}
/** /**
* Intersperse the element between the elements of the array * Intersperse the element between the elements of the array
* @param sep The element to be interspersed * @param sep The element to be interspersed
*/ */
export function intersperse<T>(sep: T, xs: T[]): T[] { export function intersperse<T>(sep: T, xs: T[]): T[] {
return concat(xs.map(x => [sep, x])).slice(1); return xs.map(x => [sep, x]).flat().slice(1);
} }
/** /**