Giter VIP home page Giter VIP logo

Comments (6)

BrainBacon avatar BrainBacon commented on May 31, 2024 2

Found a sweet way to implement this functionality. Vue has support for reading the $listeners property on a component, so I can leverage this to allow for attributes in the form of @on-some-observable which removes the necessity to have this as part of the Property component.

Additionally after a bit of digging I found that a vast majority of observables in Babylonjs (literally everything except for the VRExperienceHelper class) have the naming convention where they start with on and end with Observable, so my plan is to implement this in the following manner:

  • attributes in the form @some-name$ would become an observer using the onSomeNameObservable property on the underlying Babylonjs object. the listener will attempt to find a matching observable on the underlying object and in the event that one does not exist will attempt to match one on the scene.
  • attributes in the form @on-some-name-observable will become onSomeNameObservable and will check if an observer with that name exists only on the underlying Babylonjs object and will not attempt to match one on the scene (this is to account for custom events created by consumers of this library).

Things I haven't yet figured out:

  • how to handle the addOnce observer type. Vue does offer a .once modifier that does extend to custom events, but the observer would still exist. More experimentation is necessary to determine if this will work
  • how to dynamically remove observers. I don't know if it is completely necessary to support this.
  • how to handle any of the methods requiring an observer reference by the end consumer. I'm thinking I may leave this as an exercise to the developer to get a reference through the object itself.

I think this implementation will cover a majority of use-cases regarding observables in a clean and powerful manner. I will likely be creating an issue or pull request with Babylonjs to formalize the naming convention and clean up the remnants of observables in the VRExperienceHelper class that don't follow this convention. Luckily the VRExperienceHelper does not have a specific implementation in this library yet.

from vue-babylonjs.

BrainBacon avatar BrainBacon commented on May 31, 2024

Thanks! Yeah I haven't gotten to event integration yet, but it would be nice to have; especially with camera control events linked to vue's keybindings. There is an event bus setup on the Entity component for passing state between parent and child and even a Scene bus for interacting with the root Scene. I am unsure if leveraging that system and relying on the Entity mixin functionality would be better, or using Vue's built-in event functionality. Let me know what you're thinking if you get a chance to look over the Entity mixin functionality and bus system.

Edit
After thinking a bit about this, another option is adding an observable, event, or function type to the Property component. That may be a little more future-proof when more observable types are added and a little more flexible by enabling this for all component-types at once. The other option is to put together an Event, or Observable component. Not sure what is best here. Maybe you have some arguments one way or another?

from vue-babylonjs.

dtrinh100 avatar dtrinh100 commented on May 31, 2024

Do we have a timeline of when this feature will be released? I would love to be able to have access to events.

from vue-babylonjs.

BrainBacon avatar BrainBacon commented on May 31, 2024

I can look into it soon since I'm currently blocked by Babylonjs on the Loader stuff. I was hoping for a bit of feedback though. Would you say that an observable, event, or function prop added to the Property component would be an alright pattern for this?

from vue-babylonjs.

dtrinh100 avatar dtrinh100 commented on May 31, 2024

Yes, at least for my use case, I think adding an observable, event, or function prop would be a good pattern.

from vue-babylonjs.

BrainBacon avatar BrainBacon commented on May 31, 2024

This is now live. See the Observable documentation for details

from vue-babylonjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.