Skip to content
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

Closed
nikita-fuchs opened this issue Jul 29, 2021 · 4 comments
Closed

Global lifecycle callback function registry #106

nikita-fuchs opened this issue Jul 29, 2021 · 4 comments
Labels

Comments

@nikita-fuchs
Copy link

nikita-fuchs commented Jul 29, 2021

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:

  • Updating code from the repo overwrites the changes
  • I can't have code executed by lifecycle functions for obvious reasons

There could be two solutions:

  1. 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 like
    window.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.

  2. 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.

@kovacsv kovacsv added the engine label Jul 29, 2021
@kovacsv
Copy link
Owner

kovacsv commented Jul 29, 2021

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.

@nikita-fuchs
Copy link
Author

nikita-fuchs commented Aug 2, 2021

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.

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?

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.

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 ?

@kovacsv
Copy link
Owner

kovacsv commented Aug 12, 2021

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 ();
});

@kovacsv
Copy link
Owner

kovacsv commented Aug 12, 2021

Done in 0.7.19.

@kovacsv kovacsv closed this as completed Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants