Skip to content

Instantly share code, notes, and snippets.

View Jexordexan's full-sized avatar
:shipit:
lgtm

A Jordan Simonds Jexordexan

:shipit:
lgtm
View GitHub Profile
const name = value('Roger Rabbit')
watch(name, cb)
name.value = 'Jessica Rabbit'
// watch IS called because the 'value' property was changed, not the name itself
let name = 'Roger Rabbit'
watch(name, cb) // equal to watch('Roger Rabbit', cb)
name = 'Jessica Rabbit'
// watch is never called, name was completely reassigned
import { value, createComponent } from 'vue-function-api'
export default createComponent({
props: /* ... */,
setup(props) {
const sortField = value('created_at')
const reverse = value(false)
function changeSort(field: string, reverse: boolean) {
sortField.value = field
export default createComponent({
name: "UserAlerts",
props: {
user: Object,
alerts: Array,
},
setup(props) {
// Typescript automatically infers typeof 'props' to be:
// {
// user: ObjectConstructor,
import { value, createComponent } from 'vue-function-api'
export default createComponent({
props: /* ... */,
setup(props) {
const sort = state({
field: 'created_at',
reverse: false,
})
interface Props {
user: api.User
alerts?: api.Alert[]
}
import { prop } from 'ts-tricks-hidey-hole'
export default createComponent({
name: "UserAlerts",
props: {
user: prop<User>(Object),
alerts: prop<Alert[]>(Array),
},
setup(props) {
// Typescript infers typeof 'props' to be:
export default createComponent({
name: "UserAlerts",
props: {
user: Object as any as User,
alerts: Array as any as Alert[],
},
setup(props) {
// Typescript infers typeof 'props' to be:
// {
// user: User,
@Jexordexan
Jexordexan / props-option-1.ts
Created August 6, 2019 21:35
Medium: props option 1
interface Props {
user: api.User
alerts: api.Alert[]
}
export default createComponent({
name: "UserAlerts",
props: {
user: Object,
alerts: Array,
@Jexordexan
Jexordexan / prop-function.ts
Created August 6, 2019 21:34
Medium: Prop function
type PropType = String | Boolean | Number | Object | typeof Array
function prop<T = any>(type: PropType, options: any = {}): T {
return { type, ...options } as any
}