예제 #1
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();
        }
예제 #2
0
        internal BidirectionalMapper(object root, HtmlViewEngine contextBuilder, IGlueFactory glueFactory,
                                     IJavascriptObjectBuilderStrategyFactory strategyFactory, JavascriptBindingMode mode, IWebSessionLogger logger)
        {
            _BuilderStrategyFactory = strategyFactory ?? new StandardStrategyFactory();
            Mode    = mode;
            _Logger = logger;
            var javascriptObjecChanges = (mode == JavascriptBindingMode.TwoWay) ? (IJavascriptChangesObserver)this : null;

            Context           = contextBuilder.GetMainContext(javascriptObjecChanges);
            _SessionCache     = new SessionCacher();
            _ListenerRegister = ListenToCSharp ? new FullListenerRegister(OnCSharpPropertyChanged, OnCSharpCollectionChanged): null;
            glueFactory       = glueFactory ?? GlueFactoryFactory.GetFactory(Context, _SessionCache, this, _ListenerRegister?.On);
            _JsObjectBuilder  = new CSharpToJavascriptConverter(_SessionCache, glueFactory, _Logger);
            _RootObject       = root;
        }
예제 #3
0
        internal BidirectionalMapper(object root, HtmlViewEngine contextBuilder, IGlueFactory glueFactory,
                                     IJavascriptObjectBuilderStrategyFactory strategyFactory, JavascriptBindingMode mode, IWebSessionLogger logger)
        {
            _BuilderStrategyFactory = strategyFactory ?? new StandardStrategyFactory();
            Mode    = mode;
            _Logger = logger;
            var javascriptObjectChanges = (mode == JavascriptBindingMode.TwoWay) ? (IJavascriptChangesObserver)this : null;

            Context       = contextBuilder.GetMainContext(javascriptObjectChanges);
            _SessionCache = new SessionCacher();
            var jsUpdateHelper = new JsUpdateHelper(this, Context, () => _BuilderStrategy, _SessionCache);

            _ListenerUpdater = ListenToCSharp ? new ListenerUpdater(jsUpdateHelper) : null;
            glueFactory      = glueFactory ?? GlueFactoryFactory.GetFactory(Context, _SessionCache, this, _ListenerUpdater?.On);
            _JsObjectBuilder = new CSharpToJavascriptConverter(_SessionCache, glueFactory, _Logger);
            jsUpdateHelper.JsObjectBuilder = _JsObjectBuilder;
            _JsUpdateHelper = jsUpdateHelper;
            _RootObject     = root;

            _JsUpdateHelper.CheckUiContext();
            JsValueRoot = _JsObjectBuilder.Map(_RootObject);
            JsValueRoot.AddRef();
        }
예제 #4
0
        internal static IGlueFactory GetFactory(HtmlViewContext context, ICSharpToJsCache cacher, IJavascriptToCSharpConverter converter, ObjectChangesListener onListener)
        {
            var isMapping = context.JavascriptFrameworkIsMappingObject;

            return(isMapping ? (IGlueFactory) new GlueMappingFactory(context, cacher, converter, onListener) : new GlueFactory(context, cacher, converter, onListener));
        }