예제 #1
0
 /// <summary>
 /// Creates a new instance of the middleware
 /// </summary>
 public ReduxDevToolsMiddleware(
     ReduxDevToolsInterop reduxDevToolsInterop,
     ReduxDevToolsMiddlewareOptions options)
 {
     Options = options;
     ReduxDevToolsInterop = reduxDevToolsInterop;
     ReduxDevToolsInterop.OnJumpToState = OnJumpToState;
     ReduxDevToolsInterop.OnCommit      = OnCommit;
 }
예제 #2
0
        private static string BuildOptionsJson(ReduxDevToolsMiddlewareOptions options)
        {
            var values = new List <string>();

            values.Add($"name:\"{options.Name}\"");
            values.Add($"maxAge:{options.MaximumHistoryLength}");
            values.Add($"latency:{options.Latency.TotalMilliseconds}");
            return(string.Join(",", values));
        }
예제 #3
0
 /// <summary>
 /// Creates a new instance of the middleware
 /// </summary>
 public ReduxDevToolsMiddleware(
     ReduxDevToolsInterop reduxDevToolsInterop,
     ReduxDevToolsMiddlewareOptions options,
     IJsonSerialization jsonSerialization = null)
 {
     Options = options;
     ReduxDevToolsInterop = reduxDevToolsInterop;
     ReduxDevToolsInterop.OnJumpToState = OnJumpToState;
     ReduxDevToolsInterop.OnCommit      = OnCommit;
     JsonSerialization = jsonSerialization ?? new Serialization.NewtonsoftJsonAdapter();
 }
예제 #4
0
        internal static string GetClientScripts(ReduxDevToolsMiddlewareOptions options)
        {
            string assemblyName = typeof(ReduxDevToolsInterop).Assembly.GetName().Name;
            string optionsJson  = BuildOptionsJson(options);

            return($@"
window.{FluxorDevToolsId} = new (function() {{
	const reduxDevTools = window.__REDUX_DEVTOOLS_EXTENSION__;
	this.{ToJsInitMethodName} = function() {{}};

	if (reduxDevTools !== undefined && reduxDevTools !== null) {{
		const fluxorDevTools = reduxDevTools.connect({{ {optionsJson} }});
		if (fluxorDevTools !== undefined && fluxorDevTools !== null) {{
			fluxorDevTools.subscribe((message) => {{ 
				if (window.fluxorDevToolsDotNetInterop) {{
					const messageAsJson = JSON.stringify(message);
					window.fluxorDevToolsDotNetInterop.invokeMethodAsync('{DevToolsCallbackId}', messageAsJson); 
				}}
			}});
		}}

		this.{ToJsInitMethodName} = function(dotNetCallbacks, state) {{
			window.fluxorDevToolsDotNetInterop = dotNetCallbacks;
			state = JSON.parse(state);
			fluxorDevTools.init(state);

			if (window.fluxorDevToolsDotNetInterop) {{
				// Notify Fluxor of the presence of the browser plugin
				const detectedMessage = {{
					payload: {{
						type: '{ReduxDevToolsInterop.FromJsDevToolsDetectedActionTypeName}'
					}}
				}};
				const detectedMessageAsJson = JSON.stringify(detectedMessage);
				window.fluxorDevToolsDotNetInterop.invokeMethodAsync('{DevToolsCallbackId}', detectedMessageAsJson);
			}}
		}};

		this.{ToJsDispatchMethodName} = function(action, state) {{
			action = JSON.parse(action);
			state = JSON.parse(state);
			fluxorDevTools.send(action, state);
		}};

	}}
}})();
");
        }
예제 #5
0
 /// <summary>
 /// Creates an instance of the dev tools interop
 /// </summary>
 /// <param name="jsRuntime"></param>
 public ReduxDevToolsInterop(IJSRuntime jsRuntime, ReduxDevToolsMiddlewareOptions options)
 {
     JSRuntime = jsRuntime;
     DotNetRef = DotNetObjectReference.Create(this);
     Options   = options;
 }