Skip to content

Instantly share code, notes, and snippets.

View Kcko's full-sized avatar
🦜
fly like a bird ...

Roman Janko Kcko

🦜
fly like a bird ...
View GitHub Profile
<!-- MouseTracker.vue -->
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
const x = ref(0)
const y = ref(0)
const update = e => {
x.value = e.pageX
y.value = e.pageY
<template>
<slot :checkbox="checkbox" :toggleCheckbox="toggleCheckbox"></slot>
</template>
<script setup>
import { ref, reactive } from "vue";
const API_ENDPOINT_URL = "https://official-joke-api.appspot.com/random_joke";
const data = reactive({
<!-- Composable again -->
import { ref, onMounted } from "vue";
export default function useDogImages() {
const dogs = ref([]);
onMounted(async () => {
const response = await fetch(
"https://dog.ceo/api/breed/labrador/images/random/6"
);
<!-- DataProvider.vue -->
<template>
<slot
:data="data"
:loading="loading"
:error="error"
>
<component
:is="layouts[variant]"
:data="data"
:D Jo, přesně tak! To jste trefil naprosto přesně.
V praxi to často vypadá takhle:
"Super-Mega-Awesome-Provider-Container-Renderless-Composition-Pattern™️"
```vue
<template>
<slot v-bind="data">
<default-view v-bind="data" />
</slot>
<template>
<div>
<p>{{ props.state.label }}</p>
<button @click="props.actions.click">CLICK</button>
</div>
</template>
// DataGrid.vue
<script setup>
const props = defineProps({
items: {
type: Array,
required: true
},
// Render funkce pro transformaci dat nebo komplexní logiku
cellRenderer: {
type: Function,
// https://javascript.plainenglish.io/memory-magic-in-javascript-why-weakmaps-and-weaksets-are-your-secret-weapon-for-high-performance-62562cc24dc5
// 1. Private Data Storage Inside Classes
const privateData = new WeakMap();
class BankAccount {
constructor(balance) {
privateData.set(this, { balance });
}
// https://cdruc.com/form-composable
const router = useRouter();
const form = ref({
title: "",
content: "",
});
const isProcessing = ref(false);
const employees = [
{
id: 1,
first_name: 'Jan',
lastname: 'Novák',
age: 45,
salary: 85000,
role: 'CEO',
},
{