TypeScript
Snippets
Attendre jusqu'à un état attendu
Utilisation de delay :
import d from 'delay'
export default async function (what: () => boolean, delay: number = 100, maxTime?: number): Promise<boolean> {
const startTime = Date.now()
let f = what()
while (!f) {
if (typeof maxTime !== 'undefined' && Date.now() - startTime >= maxTime) {
break
}
await d(delay)
f = what()
}
return f
}
Usage :
await waitFor(() => user.isLoggedIn)
tsconfig.json
"compilerOptions": {
...
"target": "esnext",
"module": "esnext",
"strict": true,
"noImplicitAny": false,
"noImplicitThis": false,
...
}
Vrac
x: [String, Number, Array as () => Array<string | number>]
<script lang="ts">
import Vue from "vue"
type ComplexObjectInterface = {
testProp: string
modelName: number
}
export default Vue.extend({
props: {
propExample: {
type: Object as () => ComplexObjectInterface
}
},
data() {
return {
dataExample: "This Property Will Be Data"
}
},
computed: {
computedExample(): string {
return (
this.dataExample +
this.propExample.testProp +
"Computed Property Example"
)
}
},
methods: {
methodExample() {
this.dataExample = "This is being done in a method"
}
}
})
</script>