Skip to content

Commit

Permalink
Fixing issue #69
Browse files Browse the repository at this point in the history
  • Loading branch information
WAY2\david.desmaisons committed Feb 4, 2018
1 parent ec6493f commit 9e780e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Examples/Example.ChromiumFX.Vue.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public MainWindow()
{
Interval = TimeSpan.FromMilliseconds(100)
};
timer.Tick += (o, e) => datacontext.Count += 1 ;
timer.Tick += (o, e) => Update(datacontext);
timer.Start();
}

private static void Update(Person person) => person.Count += 1;

protected override void OnClosed(EventArgs e)
{
this.wcBrowser.Dispose();
Expand Down
27 changes: 21 additions & 6 deletions Neutronium.Core/Binding/BidirectionalMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class BidirectionalMapper : IDisposable, IJavascriptToCSharpConverter, IJ
private readonly FullListenerRegister _ListenerRegister;
private readonly List<IJsCsGlue> _UnrootedEntities = new List<IJsCsGlue>();
private readonly SessionCacher _SessionCache;
private List<Action> _UpdatesToBeReplayed;

private IJavascriptObjectBuilderStrategy _BuilderStrategy;
private IJavascriptSessionInjector _SessionInjector;
Expand Down Expand Up @@ -84,9 +85,12 @@ await RunInJavascriptContext(async () =>
res = JsValueRoot.JsValue;

await _SessionInjector.RegisterMainViewModel(res);

_IsLoaded = true;
});

_IsLoaded = true;

_UpdatesToBeReplayed?.ForEach(up => up());
_UpdatesToBeReplayed = null;
}

private void RegisterJavascriptHelper()
Expand Down Expand Up @@ -371,19 +375,30 @@ private void UpdateFromCSharpChanges(object newCSharpObject, Func<IJsCsGlue, Bri
var updater = Update(updaterBuilder, value);
updater.CleanAfterChangesOnUiThread(_ListenerRegister.Off);

if (!_IsLoaded)
if (!_IsLoaded)
{
//Changes happening on the UI thread while javascript thread is still initializing bindings
//We keep the updates here to be replayed when binding is done
_UpdatesToBeReplayed = _UpdatesToBeReplayed ?? new List<Action>();
_UpdatesToBeReplayed.Add(() => UpdateOnJavascriptContextAllContext(updater, value));
return;
}

if (Context.JavascriptFrameworkIsMappingObject)
UpdateOnJavascriptContextAllContext(updater, value);
}

private void UpdateOnJavascriptContextAllContext(BridgeUpdater updater, IJsCsGlue value)
{
if (Context.JavascriptFrameworkIsMappingObject)
{
DispatchInJavascriptContext(() => UpdateOnJavascriptContextWithMapping(updater, value));
return;
}

DispatchInJavascriptContext(() => UpdateOnJavascriptContext(updater, value));
DispatchInJavascriptContext(() => UpdateOnJavascriptContextWithoutMapping(updater, value));
}

private void UpdateOnJavascriptContext(BridgeUpdater updater, IJsCsGlue value)
private void UpdateOnJavascriptContextWithoutMapping(BridgeUpdater updater, IJsCsGlue value)
{
_BuilderStrategy.UpdateJavascriptValue(value);
updater.UpdateOnJavascriptContext(Context.ViewModelUpdater);
Expand Down

0 comments on commit 9e780e1

Please # to comment.