misskey icon indicating copy to clipboard operation
misskey copied to clipboard

Vue: Composition APIに移行

Open syuilo opened this issue 4 years ago • 28 comments

Summary

Options APiを使うメリットがない

syuilo avatar Aug 22 '21 07:08 syuilo

フォークでいくつかComposition APIに移行してるので行き詰まったところをば。

AutoComplete

this.$vm が存在しないので、第二引数にわたすものに困る。オートコンプリートの対象であるモデルを含むreactiveオブジェクトを渡すと良い

またあったら共有します

EbiseLutica avatar Aug 22 '21 09:08 EbiseLutica

globalProperties($store, $t, $tsなど)はそれぞれのエクスポートからのインポートに書き換えたほうがいいのかも?

tamaina avatar Jan 08 '22 16:01 tamaina

yes globalなプロパティはCompositionAPIに移行でき次第廃止する

syuilo avatar Jan 08 '22 16:01 syuilo

Before

<template>
<div>{{ $store.state.hoge }}</div>
</template>

Afetr

<template>
<div>{{ defaultStore.state.hoge }}</div>
</template>

<script setup>
import { defaultStore } from '@/store';
</script>
<!-- OR -->
<script>
import { defineComponent } from 'vue';
import { defaultStore } from '@/store';

export default defineComponent({
	setup() {
		return {
			defaultStore,
		}
	}
});
</script>

tamaina avatar Jan 08 '22 16:01 tamaina

ちなみにstoreに関してはプロパティアクセス自体廃止しそう https://github.com/misskey-dev/misskey/issues/8120

Before

<template>
<div>{{ $store.state.hoge }}</div>
</template>

Afetr

<template>
<div>{{ hoge }}</div>
</template>

<script setup>
import { defaultStore } from '@/store';

const hoge = defaultStore.getState('hoge');
</script>

syuilo avatar Jan 08 '22 16:01 syuilo

これって将来的にはgetStateをasyncにするということ?

tamaina avatar Jan 08 '22 16:01 tamaina

IndexedDBにするからそうね

syuilo avatar Jan 08 '22 16:01 syuilo

(というよりasyncではない期間はなさそう)

syuilo avatar Jan 08 '22 16:01 syuilo

なんかasync setup()面倒臭そう

tamaina avatar Jan 08 '22 16:01 tamaina

なんかasync setup()面倒臭そう

これがあるので https://github.com/misskey-dev/misskey/issues/8120 はとりあえず後回しにしようと思ってる

syuilo avatar Jan 08 '22 16:01 syuilo

ロードマップ

  1. CompositionAPI移行(+globalProperties廃止)
  2. PizzaxをIndexedDBに

syuilo avatar Jan 08 '22 16:01 syuilo

あら、勘違いしてたけどonMounted内でonUnmounted登録しても効果無いのかしら

https://v3.ja.vuejs.org/api/composition-api.html#%E3%83%A9%E3%82%A4%E3%83%95%E3%82%B5%E3%82%A4%E3%82%AF%E3%83%AB%E3%83%95%E3%83%83%E3%82%AF

これらのライフサイクルフック登録関数は、setup() の間にのみ、同期的に使用できます。

syuilo avatar Jan 09 '22 09:01 syuilo

あら、勘違いしてたけどonMounted内でonUnmounted登録しても効果無いのかしら

https://v3.ja.vuejs.org/api/composition-api.html#%E3%83%A9%E3%82%A4%E3%83%95%E3%82%B5%E3%82%A4%E3%82%AF%E3%83%AB%E3%83%95%E3%83%83%E3%82%AF

これらのライフサイクルフック登録関数は、setup() の間にのみ、同期的に使用できます。

Vue SFC Playgroundで試したらちゃんと呼ばれたわ

syuilo avatar Jan 09 '22 09:01 syuilo

置き換えマニュアルを書いてみた

https://gist.github.com/tamaina/43642876891ae3283987f59a195df3c9

tamaina avatar Jan 09 '22 09:01 tamaina

置き換えマニュアルを書いてみた

https://gist.github.com/tamaina/43642876891ae3283987f59a195df3c9

👍👍👍

syuilo avatar Jan 09 '22 10:01 syuilo

Vue SFC Playgroundで試したらちゃんと呼ばれたわ

呼ばれはするけどなんかWarning出てない?

tamaina avatar Jan 09 '22 10:01 tamaina

props変換スクリプト書いた

function genProps(props) {
	let ps = '';
	let df = '';

	for (const [k, v] of Object.entries(props)) {
		const name = v.required ? k : k + '?';
		const type = v.type === String ? 'string' :
			v.type === Number ? 'number' :
			v.type === Boolean ? 'boolean' :
			'any';
		ps += `\t${name}: ${type};\n`;

		if (v.default !== undefined) {
			const d = typeof v.default === 'string' ? `'${v.default}'` : v.default;
			df += `\t${k}: ${d},\n`;
		}
	}

	console.log(`const props = withDefaults(defineProps<{\n${ps}}>(), {\n${df}});`);
}

syuilo avatar Jan 15 '22 21:01 syuilo

onMounted内でonUnmounted登録

アンチパターンのような気がするけど…

tamaina avatar Feb 02 '22 20:02 tamaina

done

syuilo avatar May 14 '23 03:05 syuilo

https://github.com/SortableJS/vue.draggable.next がOptionsAPI使ってて__VUE_OPTIONS_API__をfalseにできないことが判明

syuilo avatar May 14 '23 03:05 syuilo

sortablejs直接使うしかない

EbiseLutica avatar May 14 '23 03:05 EbiseLutica

長い間メンテナンスされてないしやめたい…

syuilo avatar May 14 '23 03:05 syuilo

sortablejs直接使うしかない

なんか大変そう

syuilo avatar May 14 '23 03:05 syuilo

現状他にまともなVueラッパーライブラリが存在しない(はず)なので、https://github.com/SortableJS/vue.draggable.next を使うか自前でなんとかするかの二択しかない

syuilo avatar May 14 '23 03:05 syuilo

vue draggable、更新が3年前だしフォークでもしたら

tamaina avatar May 14 '23 03:05 tamaina

あーコード量そんな多くなさそうだしその手もあるな

syuilo avatar May 14 '23 03:05 syuilo

そもそもD&Dで要素を並び替えるのって外部ライブラリが必要なほど面倒なのかしらね

syuilo avatar Jun 04 '25 11:06 syuilo

自前で良い感じに実装できないかしら

syuilo avatar Jun 04 '25 11:06 syuilo

FYI https://github.com/SortableJS/vue.draggable.next/issues/283

syuilo avatar Jul 03 '25 23:07 syuilo

👀 https://github.com/Alfred-Skyblue/vue-draggable-plus

syuilo avatar Aug 12 '25 23:08 syuilo