Skip to content

Instantly share code, notes, and snippets.

View boutell's full-sized avatar

Tom Boutell boutell

View GitHub Profile
module.exports = {
props: {
value: Object,
field: Object,
context: Object
},
data() {
return {
next: (this.value.data !== undefined) ? this.value.data : (this.field.def || ''),
error: false
<template>
<ApostropheModal @close="$emit('close')">
<template slot="header">
<p>New {{ options.label }}</p>
</template>
<template slot="body">
<ApostropheSchemaEditor :fields="options.schema" v-model="pieceInfo" />
</template>
<template slot="footer">
<slot name="footer">
<template>
<ApostropheFieldset :field="field" :error="error">
<template slot="body">
<input v-model="next" />
</template>
</ApostropheFieldset>
</template>
<template>
<fieldset :class="cssClass">
<label class="apos-field-label">{{ field.label }}</label>
<div v-if="field.help" class="apos-field-help">{{ field.help }}</div>
<slot name="body"></slot>
</fieldset>
</template>
<template>
<div class="apos-schema">
<component
v-for="field in fields"
:is="options.components.fields[field.type]"
v-model="fieldState[field.name]"
:field="field"
:context="next.data"
/>
</div>
@boutell
boutell / gist:db0ca16e4b6de7a592cb79a4ed4a700c
Created August 17, 2018 22:11
mongodb query for first array element being "null" does not obey the usual "undefined properties match null" rule
// This will find "bar" and "woo". But it does not find "foo".
(function() {
db.dropDatabase();
db.docs.insert([{
title: 'foo',
ids: []
}, {
title: 'bar'
}, {
@boutell
boutell / gist:8ea95b723b253cc697607a1cc51dd5fb
Created March 22, 2018 15:50
Apostrophe CMS addColumns example
[
{
name: 'title',
label: 'Title'
},
{
name: 'updatedAt',
label: 'Last Updated',
partial: function(value) {
if (!value) {
// Demonstration that promises do not involve the pyramid of doom.
// Native ES6 promises - you could do it with bluebird promises too,
// in which case Promise.delay is a built-in convenience method
function delays() {
return delay(100).then(function() {
return delay(100);
}).then(function() {
return delay(100);
}).then(function() {
@boutell
boutell / reverse-linked-list.js
Created February 16, 2015 12:27
Reversing a linked list in JavaScript
var list = {
name: 'bob',
next: {
name: 'dick',
next: {
name: 'harry'
}
}
};
let firstStep = null;
if (options.count !== false) {
// Create a dummy promise
firstStep = Promise.resolve(true);
} else {
// Do actual work
firstStep = q.clone().count(name + '.id')... // etc.
}
return firstStep.then(... more promises go down ...)