Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View andreipfeiffer's full-sized avatar
🤔
thinking...

Andrei Pfeiffer andreipfeiffer

🤔
thinking...
View GitHub Profile
expect.extend({
toContainObject(received, argument) {
const pass = this.equals(received,
expect.arrayContaining([
expect.objectContaining(argument)
])
)
if (pass) {
import { Image, Dimensions } from 'react-native';
export default class RemoteImage extends Component {
constructor() {
super();
this.state = {
// this data could be static or provided by a server or api
url: 'https://...',
originalWidth: 1920,
Vue.component('User', {
template: '<span>{{ fullName }}</span>',
props: ['firstName', 'lastName'],
computed: {
fullName() {
return this.firstName + ' ' + this.lastName;
}
}
<template>
<div class="list-container">
<ul v-if="items.length">
<li v-for="item in items">
{{ item.name }}
</li>
</ul>
<p v-else>No items found.</p>
</div>
</template>
Vue.component('Counter', {
functional: true,
render(createElement, context) {
return createElement(/**/)
}
})
export default {
template: `
<transition name="slide">
...
</transition>
`
}
// global Event Bus
const eventBus = new Vue();
/* ... */
// some deeply nested component
methods: {
onClick() {
// emit a custom event on the Event Bus, not on "this" component
eventBus.$emit('save');
// parent component
template: '<Child @save="saveData" />',
methods: {
saveData() {/**/};
}
// child component
template: '<button @click="onClick">Save</button>',
methods: {
// props declaration
export default {
props: ['name', 'age']
}
// props declaration, validation & default values
export default {
props: {
name: String,
<template>
<input :value="name" @change="update"/>
</template>
<script>
export default {
methods: {
update(event) {
this.name = event.target.value;
}