C# Class React.JavaScriptEngineFactory

Handles creation of JavaScript engines. All methods are thread-safe.
Inheritance: IDisposable, IJavaScriptEngineFactory
ファイルを表示 Open project: reactjs/React.NET

Protected Properties

Property Type Description
_config IReactSiteConfiguration
_disposed bool
_engines IJsEngine>.ConcurrentDictionary
_factory Func
_fileSystem IFileSystem
_jsEngineSwitcher JavaScriptEngineSwitcher.Core.JsEngineSwitcher
_pool IJsPool
_scriptLoadException System.Exception

Public Methods

Method Description
Dispose ( ) : void

Clean up all engines

DisposeEngineForCurrentThread ( ) : void

Disposes the JavaScript engine for the current thread.

EnsureValidState ( ) : void

Ensures that this object has not been disposed, and that no error was thrown while loading the scripts.

GetEngine ( ) : IJsEngine

Gets a JavaScript engine from the pool.

GetEngineForCurrentThread ( ) : IJsEngine

Gets the JavaScript engine for the current thread. It is recommended to use GetEngine instead, which will pool/reuse engines.

JavaScriptEngineFactory ( JsEngineSwitcher jsEngineSwitcher, IReactSiteConfiguration config, IFileSystem fileSystem ) : System

Initializes a new instance of the JavaScriptEngineFactory class.

ReturnEngineToPool ( IJsEngine engine ) : void

Returns an engine to the pool so it can be reused

Protected Methods

Method Description
CreatePool ( ) : IJsPool

Creates a new JavaScript engine pool.

InitialiseEngine ( IJsEngine engine ) : void

Loads standard React and Babel scripts into the engine.

Private Methods

Method Description
EngineIsUsable ( IJsEngine engine, bool allowMsie ) : bool

Performs a sanity check to ensure the specified engine type is usable.

EnsureJsEnginesRegistered ( JsEngineSwitcher jsEngineSwitcher, bool allowMsie ) : void

Ensures that some engines have been registered with JavaScriptEngineSwitcher. IF not, registers some default engines.

EnsureReactLoaded ( IJsEngine engine ) : void

Ensures that React has been correctly loaded into the specified engine.

GetFactory ( JsEngineSwitcher jsEngineSwitcher, bool allowMsie ) : Func

Gets a factory for the most appropriate JavaScript engine for the current environment. The first functioning JavaScript engine with the lowest priority will be used.

LoadUserScripts ( IJsEngine engine ) : void

Loads any user-provided scripts. Only scripts that don't need JSX transformation can run immediately here. JSX files are loaded in ReactEnvironment.

Method Details

CreatePool() protected method

Creates a new JavaScript engine pool.
protected CreatePool ( ) : IJsPool
return IJsPool

Dispose() public method

Clean up all engines
public Dispose ( ) : void
return void

DisposeEngineForCurrentThread() public method

Disposes the JavaScript engine for the current thread.
public DisposeEngineForCurrentThread ( ) : void
return void

EnsureValidState() public method

Ensures that this object has not been disposed, and that no error was thrown while loading the scripts.
public EnsureValidState ( ) : void
return void

GetEngine() public method

Gets a JavaScript engine from the pool.
public GetEngine ( ) : IJsEngine
return IJsEngine

GetEngineForCurrentThread() public method

Gets the JavaScript engine for the current thread. It is recommended to use GetEngine instead, which will pool/reuse engines.
public GetEngineForCurrentThread ( ) : IJsEngine
return IJsEngine

InitialiseEngine() protected method

Loads standard React and Babel scripts into the engine.
protected InitialiseEngine ( IJsEngine engine ) : void
engine IJsEngine
return void

JavaScriptEngineFactory() public method

Initializes a new instance of the JavaScriptEngineFactory class.
public JavaScriptEngineFactory ( JsEngineSwitcher jsEngineSwitcher, IReactSiteConfiguration config, IFileSystem fileSystem ) : System
jsEngineSwitcher JavaScriptEngineSwitcher.Core.JsEngineSwitcher
config IReactSiteConfiguration
fileSystem IFileSystem
return System

ReturnEngineToPool() public method

Returns an engine to the pool so it can be reused
public ReturnEngineToPool ( IJsEngine engine ) : void
engine IJsEngine Engine to return
return void

Property Details

_config protected_oe property

React configuration for the current site
protected IReactSiteConfiguration _config
return IReactSiteConfiguration

_disposed protected_oe property

Whether this class has been disposed.
protected bool _disposed
return bool

_engines protected_oe property

Contains all current JavaScript engine instances. One per thread, keyed on thread ID.
protected ConcurrentDictionary _engines
return IJsEngine>.ConcurrentDictionary

_factory protected_oe property

Function used to create new JavaScript engine instances.
protected Func _factory
return Func

_fileSystem protected_oe property

File system wrapper
protected IFileSystem _fileSystem
return IFileSystem

_jsEngineSwitcher protected_oe property

The JavaScript Engine Switcher instance used by ReactJS.NET
protected JsEngineSwitcher,JavaScriptEngineSwitcher.Core _jsEngineSwitcher
return JavaScriptEngineSwitcher.Core.JsEngineSwitcher

_pool protected_oe property

Pool of JavaScript engines to use
protected IJsPool _pool
return IJsPool

_scriptLoadException protected_oe property

The exception that was thrown during the most recent recycle of the pool.
protected Exception,System _scriptLoadException
return System.Exception