private void InternalLoadComponent() { var source = NormalizeUrl(componentSource); var filenameParts = source.Split(new[] { ResourceUrl.PathSeparator }, StringSplitOptions.None); // eg: example/dist/source.js // baseUrl = /AssemblyName/example/ var sourceDepth = filenameParts.Length >= 2 ? 2 : 1; var baseUrl = ToFullUrl(string.Join(ResourceUrl.PathSeparator, filenameParts.Take(filenameParts.Length - sourceDepth))) + ResourceUrl.PathSeparator; var loadArgs = new List <string>() { Quote(baseUrl), Array(Quote(componentJavascriptName), Quote(source)) }; if (DefaultStyleSheet != null) { loadArgs.Add(Quote(NormalizeUrl(ToFullUrl(DefaultStyleSheet.ToString())))); } else { loadArgs.Add(JavascriptNullConstant); } loadArgs.Add(AsBoolean(enableDebugMode)); loadArgs.Add(AsBoolean(fileSystemWatcher != null)); webView.RegisterJavascriptObject(componentJavascriptName, component, executeCallsInUI: false); if (Plugins != null && Plugins.Length > 0) { loadArgs.Add(Array(Plugins.Select(m => Array(Quote(m.JavascriptName), Quote(NormalizeUrl(ToFullUrl(m.JavascriptSource))))))); foreach (var module in Plugins) { webView.RegisterJavascriptObject(module.JavascriptName, module.CreateNativeObject(), executeCallsInUI: false); } } else { loadArgs.Add(JavascriptNullConstant); } if (Mappings != null && Mappings.Count > 0) { loadArgs.Add(Object(Mappings.Select(m => new KeyValuePair <string, string>(Quote(m.Key), Quote(NormalizeUrl(m.Value.ToString())))))); } ExecuteDeferredScriptFunction("load", loadArgs.ToArray()); componentLoaded = true; }
private void InternalLoadComponent() { var source = NormalizeUrl(component.JavascriptSource); var filenameParts = source.Split(new[] { ResourceUrl.PathSeparator }, StringSplitOptions.None); // eg: example/dist/source.js // baseUrl = /AssemblyName/example/ var sourceDepth = filenameParts.Length >= 2 ? 2 : 1; var baseUrl = ToFullUrl(string.Join(ResourceUrl.PathSeparator, filenameParts.Take(filenameParts.Length - sourceDepth))) + ResourceUrl.PathSeparator; var loadArgs = new List <string>() { Quote(baseUrl), Array(Quote(component.NativeObjectName), Quote(component.Name), Quote(source)) }; if (DefaultStyleSheet != null) { loadArgs.Add(Quote(NormalizeUrl(ToFullUrl(DefaultStyleSheet.ToString())))); } else { loadArgs.Add(JavascriptNullConstant); } loadArgs.Add(AsBoolean(enableDebugMode)); loadArgs.Add(Quote(cacheInvalidationTimestamp)); webView.RegisterJavascriptObject(component.NativeObjectName, component.CreateNativeObject(), executeCallsInUI: false); if (Plugins?.Length > 0) { // plugins var pluginsWithNativeObject = Plugins.Where(p => !string.IsNullOrEmpty(p.NativeObjectName)).ToArray(); loadArgs.Add(Array(pluginsWithNativeObject.Select(m => Array(Quote(m.Name), Quote(m.NativeObjectName))))); foreach (var module in pluginsWithNativeObject) { webView.RegisterJavascriptObject(module.NativeObjectName, module.CreateNativeObject(), executeCallsInUI: false); } // mappings loadArgs.Add(Object(Plugins.Select(m => new KeyValuePair <string, string>(Quote(m.Name), Quote(NormalizeUrl(ToFullUrl(m.JavascriptSource))))))); } ExecuteDeferredScriptFunction("load", loadArgs.ToArray()); componentLoaded = true; }