Skip to content

Instantly share code, notes, and snippets.

View kazuooooo's full-sized avatar
:octocat:
Taking a closer look, wombat!

kazuwombat kazuooooo

:octocat:
Taking a closer look, wombat!
View GitHub Profile
this.sync(
'docData', // Document Dataと同期させたいpiniaのプロパティ名
docRef // Document Reference
)
import { PiniaFirestoreSync } from 'pinia-plugin-firestore-sync'
// Add plugin
const pinia = createPinia().use(firestoreSyncPlugin)
app.use(pinia).mount('#app'
npm install pinia-plugin-firestore-sync
async setup() {
// Yay🙌
this.sync('docDataA', docRefA)
this.sync('docDataB', docRefB)
this.sync('docDataC', docRefC)
}
async setup() {
// It's very vervose...
onSnapshot(docRefA, (ds) => {
if (ds.exists()) {
this.$patch({ docDataA: ds.data() })
}
})
onSnapshot(docRefB, (ds) => {
if (ds.exists()) {
this.$patch({ docDataB: ds.data() })
export const useExampleStore = defineStore('expamle', {
state: {/*...*/}
actions: {
async setup() {
// ...
//🌟 Sync Pinia's state and Firestore document
onSnapshot(docRef, (ds) => {
if (ds.exists()) {
this.$patch({ docData: ds.data() })
}
@kazuooooo
kazuooooo / sample1.ts
Created February 5, 2022 15:08
sample1.ts
export const useExampleStore = defineStore('expamle', {
state: {/*...*/}
actions: {
async setup() {
// ...
//🌟 docDataとdocRefを同期
onSnapshot(docRef, (ds) => {
if (ds.exists()) {
this.$patch({ docData: ds.data() })
}
@kazuooooo
kazuooooo / addMokuji.js
Created August 16, 2021 05:00
STUDIOに目次をつけるコード
var assignMokuji = function(){
/**
* 指定したテキストでH1もしくはH2要素を見つける
* @param {*} text
* @returns
*/
var findH1OrH2ByText = function(text) {
var h1 = $("h1:contains(" + text + ")").first()
if(h1[0]){
return h1[0]
@kazuooooo
kazuooooo / SimpleCarousel.vue
Created October 25, 2020 09:01
Simple carousel implementation Vue3
<template>
<div class="container">
<!-- ページをクリッピングするコンテナ -->
<div class="clipping-container">
<!-- ページ全体、このleftをtransitionでスライドさせてページを動かす -->
<div class="pages" :style="{left: currentLeft}">
<div class="page">
1
</div>
<div class="page">
import SwiftUI
struct CounterView: View {
// Data binding with CounterView Model
@EnvironmentObject var counterViewModel: CounterViewModel
var body: some View {
return VStack {
// count value updated automatically by data binding
Text(String(self.counterViewModel.count))