Beispiel #1
0
        internal async Task UpdateJavascriptObjects(bool debugMode)
        {
            await RunInJavascriptContext(async() =>
            {
                RegisterJavascriptHelper();

                Context.InitOnJsContext(debugMode);
                _SessionInjector = Context.JavascriptSessionInjector;

                _BuilderStrategy = _BuilderStrategyFactory.GetStrategy(Context.WebView, _SessionCache, Context.JavascriptFrameworkIsMappingObject);
                _BuilderStrategy.UpdateJavascriptValue(JsValueRoot);

                IJavascriptObject res;
                if (Context.JavascriptFrameworkIsMappingObject)
                {
                    res = await InjectInHtmlSession(JsValueRoot);
                }
                else
                {
                    res = JsValueRoot.JsValue;
                }

                await _SessionInjector.RegisterMainViewModel(res);

                _IsLoaded = true;
            });
        }
Beispiel #2
0
        internal BidirectionalMapper(object root, HtmlViewEngine contextBuilder, IGlueFactory glueFactory, IJavascriptObjectBuilderStrategyFactory strategyFactory,
                                     JavascriptBindingMode mode, IInternalSessionCache sessionCacher)
        {
            Mode          = mode;
            Context       = contextBuilder.GetMainContext();
            _SessionCache = sessionCacher ?? new SessionCacher();

            strategyFactory  = strategyFactory ?? new StandardStrategyFactory();
            _BuilderStrategy = new Lazy <IJavascriptObjectBuilderStrategy>(() =>
                                                                           strategyFactory.GetStrategy(Context.WebView, _SessionCache, Context.JavascriptFrameworkIsMappingObject)
                                                                           );
            _JavascriptFrameworkManager = new Lazy <IJavascriptFrameworkMapper>(() => Context.GetMapper(_SessionCache, BuilderStrategy));

            var jsUpdateHelper = new JsUpdateHelper(this, Context, _JavascriptFrameworkManager, _SessionCache);

            _JavascriptToGlueMapper = new JavascriptToGlueMapper(jsUpdateHelper, _SessionCache);

            _CSharpChangesListener    = ListenToCSharp ? new CSharpListenerJavascriptUpdater(jsUpdateHelper) : null;
            glueFactory               = glueFactory ?? GlueFactoryFactory.GetFactory(Context, _SessionCache, _JavascriptToGlueMapper, _CSharpChangesListener?.On);
            _CSharpToGlueMapper       = new CSharpToGlueMapper(_SessionCache, glueFactory, Context.Logger);
            jsUpdateHelper.GlueMapper = _CSharpToGlueMapper;

            _CSharpUnrootedObjectManager      = new CSharpUnrootedObjectManager(jsUpdateHelper, _CSharpToGlueMapper);
            glueFactory.UnrootedObjectManager = _CSharpUnrootedObjectManager;
            _JavascriptChangesListener        = (Mode == JavascriptBindingMode.TwoWay) ?
                                                new JavascriptListenerCSharpUpdater(_CSharpChangesListener, jsUpdateHelper, _JavascriptToGlueMapper) : null;

            jsUpdateHelper.CheckUiContext();
            JsValueRoot = _CSharpToGlueMapper.Map(root);
            JsValueRoot.AddRef();
        }
 private void InitOnJavascriptContext(bool debugMode)
 {
     RegisterJavascriptHelper();
     Context.InitOnJsContext(debugMode);
     _SessionInjector = Context.JavascriptSessionInjector;
     _BuilderStrategy = _BuilderStrategyFactory.GetStrategy(Context.WebView, _SessionCache, Context.JavascriptFrameworkIsMappingObject);
     _BuilderStrategy.UpdateJavascriptValue(JsValueRoot);
 }