misskey-dev / misskey

🌎 A completely free and open interplanetary microblogging platform 🚀
https://misskey-hub.net/
GNU Affero General Public License v3.0
9.97k stars 1.35k forks source link

Vue: Composition APIに移行 #7681

Open syuilo opened 3 years ago

syuilo commented 3 years ago

Summary

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

EbiseLutica commented 3 years ago

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

AutoComplete

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

またあったら共有します

tamaina commented 2 years ago

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

syuilo commented 2 years ago

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

tamaina commented 2 years ago

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>
syuilo commented 2 years ago

ちなみに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>
tamaina commented 2 years ago

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

syuilo commented 2 years ago

IndexedDBにするからそうね

syuilo commented 2 years ago

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

tamaina commented 2 years ago

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

syuilo commented 2 years ago

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

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

syuilo commented 2 years ago

ロードマップ

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

あら、勘違いしてたけど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 commented 2 years ago

あら、勘違いしてたけど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で試したらちゃんと呼ばれたわ

tamaina commented 2 years ago

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

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

syuilo commented 2 years ago

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

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

👍👍👍

tamaina commented 2 years ago

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

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

syuilo commented 2 years ago

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}});`);
}
tamaina commented 2 years ago

onMounted内でonUnmounted登録

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

syuilo commented 1 year ago

done

syuilo commented 1 year ago

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

EbiseLutica commented 1 year ago

sortablejs直接使うしかない

syuilo commented 1 year ago

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

syuilo commented 1 year ago

sortablejs直接使うしかない

なんか大変そう

syuilo commented 1 year ago

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

tamaina commented 1 year ago

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

syuilo commented 1 year ago

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