Beispiel #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="JsxTransformer"/> class.
		/// </summary>
		/// <param name="environment">The ReactJS.NET environment</param>
		/// <param name="cache">The cache to use for JSX compilation</param>
		/// <param name="fileSystem">File system wrapper</param>
		/// <param name="fileCacheHash">Hash algorithm for file-based cache</param>
		public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash)
		{
			_environment = environment;
			_cache = cache;
			_fileSystem = fileSystem;
			_fileCacheHash = fileCacheHash;
		}
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReactComponent"/> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="componentName">Name of the component.</param>
 /// <param name="containerId">The ID of the container DIV for this component</param>
 public ReactComponent(IReactEnvironment environment, string componentName, string containerId)
 {
     EnsureComponentNameValid(componentName);
     _environment   = environment;
     _componentName = componentName;
     _containerId   = containerId;
 }
Beispiel #3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="JsxTransformer"/> class.
		/// </summary>
		/// <param name="environment">The ReactJS.NET environment</param>
		/// <param name="cache">The cache to use for JSX compilation</param>
		/// <param name="fileSystem">File system wrapper</param>
		/// <param name="fileCacheHash">Hash algorithm for file-based cache</param>
		/// <param name="siteConfig">Site-wide configuration</param>
		public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig)
		{
			_environment = environment;
			_cache = cache;
			_fileSystem = fileSystem;
			_fileCacheHash = fileCacheHash;
			_config = siteConfig;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="JsxTransformer"/> class.
 /// </summary>
 /// <param name="environment">The ReactJS.NET environment</param>
 /// <param name="cache">The cache to use for JSX compilation</param>
 /// <param name="fileSystem">File system wrapper</param>
 /// <param name="fileCacheHash">Hash algorithm for file-based cache</param>
 /// <param name="siteConfig">Site-wide configuration</param>
 public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig)
 {
     _environment   = environment;
     _cache         = cache;
     _fileSystem    = fileSystem;
     _fileCacheHash = fileCacheHash;
     _config        = siteConfig;
 }
        private static void Inject(IReactEnvironment env, string name, object o)
        {
            // Engine is a protected property
            var EnginePI = env.GetType().GetProperty("Engine", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var obj      = EnginePI.GetValue(env);
            var engine   = (JavaScriptEngineSwitcher.Core.IJsEngine)obj;

            engine.EmbedHostObject(name, o);
        }
Beispiel #6
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Babel"/> class.
		/// </summary>
		/// <param name="environment">The ReactJS.NET environment</param>
		/// <param name="cache">The cache to use for compilation</param>
		/// <param name="fileSystem">File system wrapper</param>
		/// <param name="fileCacheHash">Hash algorithm for file-based cache</param>
		/// <param name="siteConfig">Site-wide configuration</param>
		public Babel(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig)
		{
			_environment = environment;
			_cache = cache;
			_fileSystem = fileSystem;
			_fileCacheHash = fileCacheHash;
			_config = siteConfig;
			_babelConfig = siteConfig.BabelConfig.Serialize();
		}
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReactComponent"/> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="configuration">Site-wide configuration.</param>
 /// <param name="componentName">Name of the component.</param>
 /// <param name="containerId">The ID of the container DIV for this component</param>
 public ReactComponent(IReactEnvironment environment, IReactSiteConfiguration configuration, string componentName, string containerId)
 {
     EnsureComponentNameValid(componentName);
     _environment   = environment;
     _configuration = configuration;
     ComponentName  = componentName;
     ContainerId    = string.IsNullOrEmpty(containerId) ? GenerateId() : containerId;
     ContainerTag   = "div";
 }
Beispiel #8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ReactComponent"/> class.
		/// </summary>
		/// <param name="environment">The environment.</param>
		/// <param name="configuration">Site-wide configuration.</param>
		/// <param name="componentName">Name of the component.</param>
		/// <param name="containerId">The ID of the container DIV for this component</param>
		public ReactComponent(IReactEnvironment environment, IReactSiteConfiguration configuration, string componentName, string containerId)
		{
			EnsureComponentNameValid(componentName);
			_environment = environment;
			_configuration = configuration;
			ComponentName = componentName;
			ContainerId = containerId;
			ContainerTag = "div";
		}
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Babel"/> class.
 /// </summary>
 /// <param name="environment">The ReactJS.NET environment</param>
 /// <param name="cache">The cache to use for compilation</param>
 /// <param name="fileSystem">File system wrapper</param>
 /// <param name="fileCacheHash">Hash algorithm for file-based cache</param>
 /// <param name="siteConfig">Site-wide configuration</param>
 public Babel(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig)
 {
     _environment   = environment;
     _cache         = cache;
     _fileSystem    = fileSystem;
     _fileCacheHash = fileCacheHash;
     _config        = siteConfig;
     _babelConfig   = siteConfig.BabelConfig.Serialize(_config.BabelVersion);
 }
 /// <summary>
 /// Initialises a new instance of the <see cref="ReactRouterComponent"/> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="configuration">Site-wide configuration.</param>
 /// <param name="componentName">Name of the component.</param>
 /// <param name="containerId">The ID of the container DIV for this component</param>
 /// <param name="path">F.x. from Request.Path. Used by React Static Router to determine context and routing.</param>
 public ReactRouterComponent(
     IReactEnvironment environment,
     IReactSiteConfiguration configuration,
     string componentName,
     string containerId,
     string path
     ) : base(environment, configuration, componentName, containerId)
 {
     _path = path;
 }
Beispiel #11
0
		/// <summary>
		/// Executes the task.
		/// </summary>
		/// <returns><c>true</c> on success</returns>
		public override bool Execute()
		{
			MSBuildHost.EnsureInitialized();
			_environment = React.AssemblyRegistration.Container.Resolve<IReactEnvironment>();

			Log.LogMessage("Starting TransformJsx");
			var stopwatch = Stopwatch.StartNew();
			var result = ExecuteInternal();
			Log.LogMessage("TransformJsx completed in {0}", stopwatch.Elapsed);
			return result;
		}
Beispiel #12
0
		/// <summary>
		/// Initializes a new instance of the <see cref="JsxHandler"/> class.
		/// </summary>
		/// <param name="environment">The environment.</param>
		/// <param name="fileSystem">File system</param>
		/// <param name="request">HTTP request</param>
		/// <param name="response">HTTP response</param>
		public JsxHandler(
			IReactEnvironment environment, 
			IFileSystem fileSystem, 
			HttpRequestBase request,
			HttpResponseBase response
		)
		{
			_environment = environment;
			_fileSystem = fileSystem;
			_request = request;
			_response = response;
		}
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BabelHandler"/> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="fileSystem">File system</param>
 /// <param name="request">HTTP request</param>
 /// <param name="response">HTTP response</param>
 public BabelHandler(
     IReactEnvironment environment,
     IFileSystem fileSystem,
     HttpRequestBase request,
     HttpResponseBase response
     )
 {
     _environment = environment;
     _fileSystem  = fileSystem;
     _request     = request;
     _response    = response;
 }
Beispiel #14
0
		/// <summary>
		/// Executes the task.
		/// </summary>
		/// <returns><c>true</c> on success</returns>
		public override bool Execute()
		{
			MSBuildHost.EnsureInitialized();
			var config = React.AssemblyRegistration.Container.Resolve<IReactSiteConfiguration>();
			config
				.SetReuseJavaScriptEngines(false);

			_environment = ReactEnvironment.Current;

			Log.LogMessage("Starting Babel transform");
			var stopwatch = Stopwatch.StartNew();
			var result = ExecuteInternal();
			Log.LogMessage("Babel transform completed in {0}", stopwatch.Elapsed);
			return result;
		}
Beispiel #15
0
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <returns><c>true</c> on success</returns>
        public override bool Execute()
        {
            MSBuildHost.EnsureInitialized();
            var config = React.AssemblyRegistration.Container.Resolve <IReactSiteConfiguration>();

            config.UseHarmony = UseHarmony;

            _environment = React.AssemblyRegistration.Container.Resolve <IReactEnvironment>();

            Log.LogMessage("Starting TransformJsx");
            var stopwatch = Stopwatch.StartNew();
            var result    = ExecuteInternal();

            Log.LogMessage("TransformJsx completed in {0}", stopwatch.Elapsed);
            return(result);
        }
Beispiel #16
0
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <returns><c>true</c> on success</returns>
        public override bool Execute()
        {
            MSBuildHost.EnsureInitialized();
            var config = React.AssemblyRegistration.Container.Resolve <IReactSiteConfiguration>();

            config
            .SetReuseJavaScriptEngines(false);

            _environment = React.AssemblyRegistration.Container.Resolve <IReactEnvironment>();

            Log.LogMessage("Starting Babel transform");
            var stopwatch = Stopwatch.StartNew();
            var result    = ExecuteInternal();

            Log.LogMessage("Babel transform completed in {0}", stopwatch.Elapsed);
            return(result);
        }
        public BabelJavascriptPreprocessor(bool includeSourceMaps)
        {
            this.includeSourceMaps = includeSourceMaps;
            Initializer.Initialize(r => r.AsSingleton());

            var container = AssemblyRegistration.Container;

            container.Register <ICache, NullCache>();
            container.Register <IFileSystem, SimpleFileSystem>();
            ReactSiteConfiguration.Configuration.SetReuseJavaScriptEngines(true);

            JsEngineSwitcher.Current.DefaultEngineName = MsieJsEngine.EngineName;
            JsEngineSwitcher.Current.EngineFactories.AddMsie();

            this.reactEnvironment = ReactEnvironment.Current;

            this.reactEnvironment.Configuration.BabelConfig.Presets.Remove("react");

            this.babelConfig = this.reactEnvironment.Configuration.BabelConfig.Serialize();
        }
        /// <summary>
        /// Create a React Router Component with context and add it to the list of components to render client side,
        /// if applicable.
        /// </summary>
        /// <typeparam name="T">Type of the props</typeparam>
        /// <param name="env">React Environment</param>
        /// <param name="componentName">Name of the component</param>
        /// <param name="props">Props to use</param>
        /// <param name="path">F.x. from Request.Path. Used by React Static Router to determine context and routing.</param>
        /// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
        /// <param name="clientOnly">True if server-side rendering will be bypassed. Defaults to false.</param>
        /// <returns></returns>
        public static ReactRouterComponent CreateRouterComponent <T>(
            this IReactEnvironment env,
            string componentName,
            T props,
            string path,
            string containerId = null,
            bool clientOnly    = false
            )
        {
            var component = new ReactRouterComponent(
                env,
                AssemblyRegistration.Container.Resolve <IReactSiteConfiguration>(),
                AssemblyRegistration.Container.Resolve <IReactIdGenerator>(),
                componentName,
                containerId,
                path
                )
            {
                Props = props,
            };

            return(env.CreateComponent(component, clientOnly) as ReactRouterComponent);
        }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReactComponent"/> class.
 /// </summary>
 /// <param name="environment">The environment.</param>
 /// <param name="componentName">Name of the component.</param>
 /// <param name="containerId">The ID of the container DIV for this component</param>
 public ReactComponent(IReactEnvironment environment, string componentName, string containerId)
 {
     _environment   = environment;
     _componentName = componentName;
     _containerId   = containerId;
 }
Beispiel #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BabelCompiler"/> class.
 /// </summary>
 /// <param name="environment">The ReactJS.NET environment</param>
 public BabelCompiler(IReactEnvironment environment)
 {
     _environment = environment;
 }
Beispiel #21
0
		/// <summary>
		/// Initializes a new instance of the <see cref="JsxCompiler"/> class.
		/// </summary>
		/// <param name="environment">The ReactJS.NET environment</param>
		public JsxCompiler(IReactEnvironment environment)
		{
			_environment = environment;
		}
Beispiel #22
0
 public JsExecutor(string javascript)
 {
     this.javascript       = javascript;
     this.reactEnvironment = ReactEnvironment.Current;
     this.reactEnvironment.Configuration.BabelConfig.Presets.Remove("react");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BabelBundleProcessor"/> class.
 /// </summary>
 /// <param name="settings">Cassette settings.</param>
 /// <param name="environment">The ReactJS.NET environment</param>
 public BabelBundleProcessor(CassetteSettings settings, IReactEnvironment environment)
 {
     _settings    = settings;
     _environment = environment;
 }
Beispiel #24
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BabelCompiler"/> class.
		/// </summary>
		/// <param name="environment">The ReactJS.NET environment</param>
		public BabelCompiler(IReactEnvironment environment)
		{
			_environment = environment;
		}
Beispiel #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsxCompiler"/> class.
 /// </summary>
 /// <param name="environment">The ReactJS.NET environment</param>
 public JsxCompiler(IReactEnvironment environment)
 {
     _environment = environment;
 }
Beispiel #26
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ReactComponent"/> class.
		/// </summary>
		/// <param name="environment">The environment.</param>
		/// <param name="componentName">Name of the component.</param>
		/// <param name="containerId">The ID of the container DIV for this component</param>
		public ReactComponent(IReactEnvironment environment, string componentName, string containerId)
		{
			_environment = environment;
			_componentName = componentName;
			_containerId = containerId;
		}