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
Global lifecycle callback function registry #106
Comments
If I understand correctly, basically you are talking about an API for the application, so third-party codes can easily handle events. Instead of adding them to the global window object I'd prefer to send the set of event handlers to the Website class. I think this is doable, but of course, option 2 can work, too. To plan this kind of functionality I'd like to know exactly what kind of events are you interested in, and in which ways do you want to alter the behavior. |
Sounds good to me, but (correct me if I'm wrong) if things get passed to a class again, will I be able to hook into what's going on inside?
Best thing would be a generic solution for read (and maybe write) access of stateful data as well as ways to hook into the relevant callbacks once some data becomes available. One example would be access to the data shown in the UI, and being notified about when an object is loaded. Regarding "write access" I'm rather thinking about setters right now, like programatically loading a new model (which should have an accessible function existing for I think ?), and triggering it to play an animation, for example. Do glb and obj file formats and also - theoretically - allow for messing with texture data inside the editor, like e.g. replacing a texture ? |
Some callbacks are implemented, you can use them this way: $(window).on ('load', function () {
let website = new OV.Website ({
headerDiv : $('#header'),
toolbarDiv : $('#toolbar'),
mainDiv : $('#main'),
introDiv : $('#intro'),
navigatorDiv : $('#main_navigator'),
sidebarDiv : $('#main_sidebar'),
viewerDiv : $('#main_viewer'),
fileInput : $('#open_file'),
eventHandler : (name, parameters) => {
if (name === 'model_load_started') {
console.log (parameters);
} else if (name === 'model_loaded') {
console.log (parameters);
} else if (name === 'model_load_failed') {
console.log (parameters);
} else if (name === 'toolbar_clicked') {
console.log (parameters);
} else if (name === 'sidebar_clicked') {
console.log (parameters);
}
}
});
website.Load ();
}); |
Done in 0.7.19. |
Hey, currently I have to jam into your libraries to access the data "from outside" and get some notification about relevant events. This leads to two issues:
There could be two solutions:
The window object could get a
lifeCycleCallbacks
property with a dictionary representing all lifecycle functions. Inside the code of your functions, you'd simple copy-paste a new line likewindow.lifeCycleCallbacks[arguments.callee.name] != undefined ? window.lifeCycleCallbacks[arguments.callee.name]() : false
which will run the function I passed there before, for that specific lifecycle function.You could point me how to monkey-patch functions in this OOP class conundrum if that is possible ;) Then I would just monkey-patch the relevant callback functions and jam my code into them.
That would allow me to know e.g. when and what specific data is available. Thanks.
The text was updated successfully, but these errors were encountered: