Skip to content

Conversation

@neuecc
Copy link
Collaborator

@neuecc neuecc commented Feb 23, 2017

I'm trying ReactiveProperty<T> as serializable.
It is useful to restore state, used from serialize ViewModel.

Ofcourse subscriptions can not serialize but value is possible.

ReactiveProperty needs three states to deserialize.
LatestValue and ReactivePropertyMode and RaiseEventScheduler.

If ReactiveProperty expose there properties, external serializer's type resolver can it.

@runceel
Copy link
Owner

runceel commented Feb 23, 2017

Is scheduler serializable?
I want to test.

@neuecc
Copy link
Collaborator Author

neuecc commented Feb 23, 2017

This repository is my experimental (very fast!)serializer and concept design of extension for ReactiveProperty.
https://github.com/neuecc/MessagePack-CSharp/blob/master/src/MessagePack.ReactiveProperty/Formatters.cs

All schedulers are singleton so I serialize id for there well-known instance.

@neuecc
Copy link
Collaborator Author

neuecc commented Feb 26, 2017

I've released MessagePack C# 0.1.0-beta, you can test it.

Install-Package MessagePack.ReactiveProperty -Pre

Minimum sample is here.

using MessagePack;
using MessagePack.ReactivePropertyExtension;
using MessagePack.Resolvers;
using Reactive.Bindings;
using System;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        SynchronizationContext.SetSynchronizationContext(new NullContext());

        // settings(use ReactiveProperty Extension for MessagePack C#)
        CompositeResolver.RegisterAndSetAsDefault(
            ReactivePropertyResolver.Instance,
            DefaultResolver.Instance);

        var rxProp = new ReactiveProperty<int>(999);

        // to serialized binary
        var serialized = MessagePack.MessagePackSerializer.Serialize(rxProp);

        // check serialized binary
        Console.WriteLine(MessagePackSerializer.ToJson(serialized)); // [3, -1, 999]

        // check deserialization
        var deserialized = MessagePack.MessagePackSerializer.Deserialize<ReactiveProperty<int>>(serialized);
        Console.WriteLine(deserialized.Value);
    }
}

public class NullContext : SynchronizationContext
{

}

and serialize ViewModel test sample is here.
https://github.com/neuecc/MessagePack-CSharp/blob/master/tests/MessagePack.Tests/ExtensionTests/ReactivePropertyTest.cs

MessagePack C# is introduced SerializationConstructor and IMessagePackSerializationCallbackReceiver
There are enables to deserialize ReactiveProperty's ViewModel.

@runceel runceel merged commit a559553 into master Feb 26, 2017
@neuecc neuecc deleted the make-serializable branch March 2, 2017 12:36
@neuecc
Copy link
Collaborator Author

neuecc commented Mar 3, 2017

Thank you for release 3.5.1.
I've update dependency and use there public property.
MessagePack-CSharp/MessagePack-CSharp@dacad1e

I'll release this packages soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants