This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let name = 'Roger Rabbit' | |
watch(name, cb) // equal to watch('Roger Rabbit', cb) | |
name = 'Jessica Rabbit' | |
// watch is never called, name was completely reassigned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default createComponent({ | |
name: "UserAlerts", | |
props: { | |
user: Object, | |
alerts: Array, | |
}, | |
setup(props) { | |
// Typescript automatically infers typeof 'props' to be: | |
// { | |
// user: ObjectConstructor, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { value, createComponent } from 'vue-function-api' | |
export default createComponent({ | |
props: /* ... */, | |
setup(props) { | |
const sort = state({ | |
field: 'created_at', | |
reverse: false, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Props { | |
user: api.User | |
alerts?: api.Alert[] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Props { | |
user: api.User | |
alerts: api.Alert[] | |
} | |
export default createComponent({ | |
name: "UserAlerts", | |
props: { | |
user: Object, | |
alerts: Array, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PropType = String | Boolean | Number | Object | typeof Array | |
function prop<T = any>(type: PropType, options: any = {}): T { | |
return { type, ...options } as any | |
} |
NewerOlder