-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Async .net side waiter for bound objects #2362
Comments
Adding a custom set of I was originally tossing up between
Do you think a totally new event specially for this purpose would be preferable? If so what would it be called?
My initial though on automatically binding objects upon context creation were that it's not particularly helpful when void IRenderProcessMessageHandler.OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
frame.ExecuteJavaScriptAsync("CefSharp.BindObjectAsync();");
} The advantage of executing the code in the Probably need a semi real work use case to make sure whatever option choose is easy enough to use. |
I thought about modifying the current event, I would consider that a breaking change however as if you currently count on it to only fire on first bind it now is called more often. I am happy with that solution though not sure about others although at 63 is fairly new it may not be a big deal. ObjectBoundInJavascript is fine I think. In JS users may call it once or over multiple lines. I agree allowing users to control when object bind is useful, especially as if they do want autobinding they can implement something like OnContextCreated. The main goal of all of this was just to give a way from c# to make sure something is bound. If there is a new function or existing function with args that is always called is greatly simplifies a helper class to something like the following: Helper.cs |
Can modify would be something like I'd also change the event args to add extra properties, |
I would vote for first on a method that takes an open ended array of args. Any of these changes sound great. |
Marking this as |
…ository.ObjectsBound event This contains the breaking changes required for #2362
A rough implementation was merged into TODO
As it's not ready for wide spread release yet, I've merged the breaking changes into the Will look at releasing a Let me know what you think. You can see the new |
Syntax and event args seem easy to follow will certainly simplify binding resolution from .net as well. |
Suggestions on naming welcome 😃 |
I assume the only items you are asking for naming feedback on are the new NotifyIfAlreadyBound / IgnoreCache options? The naming seems straightforward enough and while it is easy to use them as is I do wonder if NotifyIfAlreadyBound isn't better done as an option from the .net side rather than JS. It is a minor point however. NotifyEvenIfAlreadyBound, AlwaysGenerateEvent, AlwaysGenerateNotification, ForceNotify if you are looking for other options. |
From
Probably just go with the current name unless there's a strong opinion for something else. |
To support this use case added IJavascriptObjectRepository.ObjectsBoundInJavascript (called a single time with names of all objects bound) Implements the idea put forward in #2362
Have added Example looks something like: browser.EnsureObjectBoundAsync("bound").ContinueWith(t =>
{
var boundObjects = t.Result;
}); Obviously you can |
ObjectsBoundInJavascript certainly simplifies it and as a user can use either shouldn't make it too difficult for users. EnsureObjectBound helper will likely be useful for others so should make a nice addition for transitioning existing code. |
To support this use case added IJavascriptObjectRepository.ObjectsBoundInJavascript (called a single time with names of all objects bound) Implements the idea put forward in #2362 # Conflicts: # CefSharp/Internals/JavascriptObjectRepository.cs
Section added to the I'm not totally happy with the formatting, overall the whole |
The documentation still needs some work, so I've creating #2455 |
I mentioned this briefly previously but I think it might be of value to have a .net side task that you could await for an object to be bound into existence. This can be partially accomplished with the nice ObjectBoundInJavascript event but as it doesn't fire if already bound it cannot be done as easily.
This may make it easier for people to move from the old binding to the new binding system if they only
use bound objects to exfil data from JS and not get results of methods.
It allows for something like:
Attached is a .net helper class that emulates the process that I could see being used. It has added complexity as we cannot tell from .net if an object is already bound (I guess could call EvaluateScriptAsync to test each window object). This could be resolved with another event handler of ObjectAlreadyBoundInJavascript called for any time bindobjectasync is called with an already bound object.
Helper.cs
Let me know thoughts or if worthwhile. This helper works for me (and actually could be simplified to just wait for BindObjectAsync rather than resolving after each bound object). Part of the current flow is to show what would be possible with the additional event handler, just one line of code with no helper class bound into the JS namespace. It could be taken a step further with no JS injection if the bind call was possible from .net code.
The text was updated successfully, but these errors were encountered: