-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create CreateApp #79
Create CreateApp #79
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Fireworks Application | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Implementation steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* 1. Set up the Vue application using createApp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* 2. Manage state with reactive properties for fireworks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* 3. Add sound effects using Audio API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* 4. Create explosion callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* 5. Integrate with firework library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { createApp } from 'vue'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const app = createApp({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
data() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fireworks: [], // Array to hold firework objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sounds: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
explosion: new Audio('path/to/explosion.mp3'), // Sound effect for explosion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
methods: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
addFirework(firework) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.fireworks.push(firework); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
playExplosionSound(firework) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.sounds.explosion.play(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
handleFireworkExplosion(firework) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// This method will be called when a firework explodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.playExplosionSound(firework); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// You can add more logic here if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+23
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance method implementations with proper validation and error handling The current methods lack proper validation and error handling mechanisms. addFirework(firework) {
+ if (!firework || typeof firework !== 'object') {
+ console.error('Invalid firework object');
+ return;
+ }
this.fireworks.push(firework);
},
playExplosionSound(firework) {
+ if (!this.sounds.explosion) {
+ console.warn('Sound not initialized');
+ return;
+ }
+ // Reset sound to allow rapid replays
+ this.sounds.explosion.currentTime = 0;
this.sounds.explosion.play()
+ .catch(error => console.error('Failed to play sound:', error));
},
handleFireworkExplosion(firework) {
- // This method will be called when a firework explodes
+ if (!firework || !this.fireworks.includes(firework)) {
+ console.error('Invalid firework object in explosion handler');
+ return;
+ }
this.playExplosionSound(firework);
- // You can add more logic here if needed
+ // Emit event for parent components
+ this.$emit('firework-exploded', firework);
}, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mounted() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Example of adding a firework and simulating an explosion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const newFirework = { id: 1, exploded: false }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.addFirework(newFirework); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
setTimeout(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
newFirework.exploded = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.handleFireworkExplosion(newFirework); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, 2000); // Simulate explosion after 2 seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+35
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove example code and implement proper initialization The current mounted hook contains example code that should not be in production. Additionally, the timeout should be properly cleaned up. -mounted() {
- // Example of adding a firework and simulating an explosion
- const newFirework = { id: 1, exploded: false };
- this.addFirework(newFirework);
- setTimeout(() => {
- newFirework.exploded = true;
- this.handleFireworkExplosion(newFirework);
- }, 2000); // Simulate explosion after 2 seconds
-},
+created() {
+ // Initialize audio
+ this.initializeAudio();
+},
+beforeUnmount() {
+ // Cleanup
+ if (this.sounds.explosion) {
+ this.sounds.explosion.pause();
+ this.sounds.explosion = null;
+ }
+}, Consider creating a proper interface for firework initialization: // In a separate firework.js file
export class Firework {
constructor(config = {}) {
this.id = crypto.randomUUID();
this.exploded = false;
this.config = config;
}
} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
app.mount('#app'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for audio initialization
The current audio initialization lacks error handling and could fail silently. Consider implementing proper error handling and feature detection.
Add this to the mounted hook: