Skip to content

Instantly share code, notes, and snippets.

View asoglovo's full-sized avatar

Angel Sola asoglovo

  • Glovo
  • Barcelona
View GitHub Profile
<script>
import { createEventDispatcher } from "svelte";
export let cell;
export let overrideVisible = false;
const dispatch = new createEventDispatcher();
function unhideCell() {
if (cell.hasMine) {
@asoglovo
asoglovo / helloComponentRenderFunction.js
Created February 5, 2020 16:53
"<h1>Hello, {{ name }}</h1>" template converted to a render function by Vue3 compiler
(function anonymous(Vue) {
const _Vue = Vue
return function render() {
with (this) {
const {
toDisplayString: _toDisplayString,
createVNode: _createVNode,
createBlock: _createBlock,
openBlock: _openBlock
@asoglovo
asoglovo / vue3_finishComponentSetup_simplified.ts
Last active February 26, 2020 07:42
Vue 3 finishComponentSetup function (runtime-core > component.ts) with some elided details
function finishComponentSetup(
instance: ComponentInternalInstance
/* elided argument */
) {
const Component = instance.type as ComponentOptions
if (Component.template && !Component.render) {
Component.render = compile!(Component.template /* elided arg */)
}
/* elided details */
@asoglovo
asoglovo / vue3_patch_simplified.ts
Last active February 7, 2020 16:12
Vue3 patch function simplified
function patch(
n1: HostVNode | null
n2: HostVNode,
container: HostElement
/* elided arguments */
) {
/* elided */
const { type, shapeFlag } = n2
switch (type) {
@asoglovo
asoglovo / vue3_vnode.type.ts
Last active February 7, 2020 10:47
Vue 3 VNode type (runtime-core / vnode.ts)
export interface VNode<HostNode = any, HostElement = any> {
_isVNode: true
type: VNodeTypes
props: VNodeProps | null
/* elided */
children: VNodeNormalizedChildren<HostNode, HostElement>
component: ComponentInternalInstance | null
/* elided */
// DOM
@asoglovo
asoglovo / PaymentWithCard.spec.factory.js
Created January 20, 2020 13:44
Using the builder pattern to mount Vue component wrappers
import { shallowMount } from '@vue/test-utils'
import PaymentWithCard from '@/components/PaymentWithCard.vue'
export default function() {
let amountInEuros = 100
let cardNumber = null,
cardHolder = null,
expirationDate = null
let successMsgSpy = jest.fn()
let errorMsgSpy = jest.fn()
@asoglovo
asoglovo / PaymentWithCard.spec.js
Created January 20, 2020 13:41
Test for the PaymentWithCard component
import testWrapperBuilder from './PaymentWithCard.spec.factory'
import api from '@/api/paymentAPI'
jest.mock('@/api/paymentAPI', function() {
return { pay: jest.fn() }
})
describe('Payment with card', () => {
beforeEach(() => {
jest.clearAllMocks()
@asoglovo
asoglovo / PaymentWithCard.vue
Created January 20, 2020 13:35
Vue example component: payment with card
<script>
import paymentAPI from '@/api/paymentAPI'
export default {
name: 'PaymentWithCard',
props: ['amountInEuros'],
data() {
return {