private void OnJumpToState(object sender, JumpToStateCallback e) { SequenceNumberOfCurrentState = e.payload.actionId; using (Store.BeginInternalMiddlewareChange()) { var newFeatureStates = (IDictionary <string, object>)Json.Deserialize <object>(e.state); foreach (KeyValuePair <string, object> newFeatureState in newFeatureStates) { // Get the feature with the given name if (!Store.Features.TryGetValue(newFeatureState.Key, out IFeature feature)) { continue; } // Get the generic method of JsonUtil.Deserialize<> so we have the correct object type for the state string deserializeMethodName = nameof(Json.Deserialize); MethodInfo deserializeMethodInfo = typeof(Json) .GetMethod(deserializeMethodName) .GetGenericMethodDefinition() .MakeGenericMethod(new Type[] { feature.GetStateType() }); // Get the state we were given as a json string string serializedFeatureState = newFeatureState.Value?.ToString(); // Deserialize that json using the generic method, so we get an object of the correct type object stronglyTypedFeatureState = string.IsNullOrEmpty(serializedFeatureState) ? null : deserializeMethodInfo.Invoke(null, new object[] { serializedFeatureState }); // Now set the feature's state to the deserialized object feature.RestoreState(stronglyTypedFeatureState); } } }
private Task OnJumpToState(JumpToStateCallback callbackInfo) { SequenceNumberOfCurrentState = callbackInfo.payload.actionId; using (Store.BeginInternalMiddlewareChange()) { var newFeatureStates = Json.Deserialize <Dictionary <string, object> >(callbackInfo.state); foreach (KeyValuePair <string, object> newFeatureState in newFeatureStates) { // Get the feature with the given name if (!Store.Features.TryGetValue(newFeatureState.Key, out IFeature feature)) { continue; } var serializedFeatureStateElement = (JsonElement)newFeatureState.Value; object stronglyTypedFeatureState = Json.Deserialize( json: serializedFeatureStateElement.ToString(), returnType: feature.GetStateType(), options: SerializationOptions); // Now set the feature's state to the deserialized object feature.RestoreState(stronglyTypedFeatureState); } } return(Task.CompletedTask); }
private async Task OnJumpToState(JumpToStateCallback callbackInfo) { // Wait for fire+forget state notifications to ReduxDevTools to dequeue await TailTask.ConfigureAwait(false); SequenceNumberOfCurrentState = callbackInfo.payload.actionId; using (Store.BeginInternalMiddlewareChange()) { var newFeatureStates = JsonConvert.DeserializeObject <Dictionary <string, object> >(callbackInfo.state); foreach (KeyValuePair <string, object> newFeatureState in newFeatureStates) { // Get the feature with the given name if (!Store.Features.TryGetValue(newFeatureState.Key, out IFeature feature)) { continue; } object stronglyTypedFeatureState = JsonConvert.DeserializeObject( value: newFeatureState.Value.ToString(), type: feature.GetStateType()); // Now set the feature's state to the deserialized object feature.RestoreState(stronglyTypedFeatureState); } } }
private void OnJumpToState(JumpToStateCallback jumpToStateCallback) { JumpToState?.Invoke(null, jumpToStateCallback); AfterJumpToState?.Invoke(null, EventArgs.Empty); }