Last active
October 21, 2018 17:56
-
-
Save Mirzero/6173ee7e9e607352623425caebf0048a to your computer and use it in GitHub Desktop.
Simple clock experiment in Vue that isn't quite working...
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 class Clock { | |
TickTimeout: number = 50; | |
TickCallback!: Function; | |
IsPaused: boolean = false; | |
LastTickTime!: number; | |
Start(tickCallback?:Function) { | |
if (tickCallback !== undefined) { | |
this.TickCallback = tickCallback; | |
} else { | |
this.TickCallback = () => { }; | |
} | |
this.LastTickTime = performance.now(); | |
this.Tick(); | |
} | |
Tick(): number { | |
var now = performance.now(); | |
var deltaMs = now - this.LastTickTime; | |
this.LastTickTime = now; | |
setTimeout(this.Tick, this.TickTimeout); | |
this.TickCallback(deltaMs); | |
return deltaMs; | |
} | |
} |
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
<!-- src/components/ClockDisplay.vue --> | |
<template> | |
<div id="clock-display-container"> | |
Tick History: {{ tickHistory }} | |
</div> | |
</template> | |
<script lang="ts"> | |
import { Vue, Component, Prop } from "vue-property-decorator"; | |
@Component | |
export default class ClockDisplay extends Vue { | |
@Prop() tickHistory!: number[]; | |
} | |
</script> | |
<style lang="scss"> | |
</style> |
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 class ClockHistory { | |
TickHistory: number[] = []; | |
Tick(deltaMs:number){ | |
this.TickHistory.push(deltaMs); | |
} | |
} |
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
<!-- src/components/GameCore.vue --> | |
<template> | |
<div id="container"> | |
<ClockDisplay :tickHistory="ClockHistory.TickHistory"/> | |
</div> | |
</template> | |
<script lang="ts"> | |
import { Clock } from "../classes/Clock"; | |
import { ClockHistory } from "../classes/ClockHistory"; | |
import { Vue, Component, Prop } from "vue-property-decorator"; | |
import ClockDisplay from "./ClockDisplay.vue"; | |
@Component({ | |
components: { | |
ClockDisplay | |
} | |
} | |
) | |
export default class Core extends Vue { | |
Clock!: Clock; | |
ClockHistory!: ClockHistory; | |
created() { | |
this.Clock = new Clock(); | |
this.ClockHistory = new ClockHistory(); | |
this.Clock.Start(this.ClockHistory.Tick); | |
} | |
} | |
</script> | |
<style lang="scss"> | |
</style> |
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
10:27:20.082 [Vue warn]: Error in created hook: "TypeError: this.TickHistory is undefined" | |
found in | |
---> <Core> at src/components/Core.vue | |
<Root> vue.esm.js:591 | |
10:27:20.083 TypeError: "this.TickHistory is undefined" | |
Tickwebpack-internal:///./src/classes/ClockHistory.ts:8:9Tickwebpack-internal:///./src/classes/Clock.ts:22:9Startwebpack-internal:///./src/classes/Clock.ts:15:9createdwebpack-internal:///./node_modules/ts-loader/index.js?!./node_modules/vue-loader/lib/index.js?!./src/components/Core.vue?vue&type=script&lang=ts&:37:9callHookwebpack-internal:///./node_modules/vue/dist/vue.esm.js:2920:9_initwebpack-internal:///./node_modules/vue/dist/vue.esm.js:4618:5VueComponentwebpack-internal:///./node_modules/vue/dist/vue.esm.js:4786:7createComponentInstanceForVnodewebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:4305:10initwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:4126:45createComponentwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:5596:9createElmwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:5543:9patchwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:6118:9_updatewebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:2659:16updateComponentwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:2787:7getwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:3141:13Watcherwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:3130:7mountComponentwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:2794:3mountwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:8528:10mountwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:10927:10_initwebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:4628:7Vuewebpack-internal:///./src/node_modules/vue/dist/vue.esm.js:4717:3<anonymous>webpack-internal:///./src/index.ts:7:9tsfile:///D:/Projects/Programming/FormicariumJS/dist/build.js:436:1__webpack_require__file:///D:/Projects/Programming/FormicariumJS/dist/build.js:20:12<anonymous>file:///D:/Projects/Programming/FormicariumJS/dist/build.js:84:18<anonymous>file:///D:/Projects/Programming/FormicariumJS/dist/build.js:1:11 vue.esm.js:1741 | |
10:27:20.121 You are running Vue in development mode. | |
Make sure to turn on production mode when deploying for production. | |
See more tips at https://vuejs.org/guide/deployment.html vue.esm.js:8566 | |
10:27:20.122 You are running Vue in development mode. | |
Make sure to turn on production mode when deploying for production. | |
See more tips at https://vuejs.org/guide/deployment.html vue.esm.js:8566 | |
10:27:20.149 [Show/hide message details.] TypeError: this.TickCallback is not a function[Learn More] build.js line 316 > eval:22:9 |
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
<!doctype html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
</head> | |
<body> | |
<div id="app"></div> | |
</body> | |
<script src="./dist/build.js"></script> | |
</html> |
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
// src/index.ts | |
import Vue from "vue"; | |
import Core from "./components/Core.vue"; | |
let v = new Vue({ | |
el: "#app", | |
template: | |
`<Core />`, | |
propsData: { | |
}, | |
components: { | |
Core, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment