Exemple #1
0
        public static JavaScriptValue Import(string specifier, Action <string> fileChangedCallback = null)
        {
            JavaScriptValue module = JavaScriptValue.Null;

            Module.RecordDelegate recordDelegate = null;
            Engine.With(() => {
                module = Module.Loader.Load(javascriptRoot, specifier, out recordDelegate);
            });

            if (fileChangedCallback != null)
            {
                string path = new JavaScript.Module.Resolver(javascriptRoot).Normalize(null, specifier);
                fileChangedCallbacks[path] = fileChangedCallback;

                if (recordDelegate != null)
                {
                    foreach (var item in recordDelegate.dependencies)
                    {
                        string dependencyPath = item.HostUrl;
                        fileChangedCallbacks[dependencyPath] = fileChangedCallback;
                    }
                }
            }

            return(module);
        }
Exemple #2
0
        public static JavaScriptValue Load(string rootDir, string specifier, out RecordDelegate recordDelegate, Cache passedCache = null)
        {
            Loader.Debug($"Javascript.Module.Loader.Load('{rootDir}', '{specifier}')");
            Cache cache = passedCache == null ? defaultCache : passedCache;

            var path = new JavaScript.Module.Resolver(rootDir).Normalize(null, specifier);

            if (path != null && cache.Has(path))
            {
                recordDelegate = null; // TODO ?????
                return(JavaScriptValue.GlobalObject.GetProperty(modulesSymbol).GetProperty(specifier));
            }

            RecordDelegate moduleRecordDelegate = new RecordDelegate(rootDir, cache);

            moduleRecordDelegate.Run($@"
        import * as mod from '{specifier}';
        global[Symbol.for('typescript-for-unity.importedRootModules')]['{specifier}'] = Object.assign({{}}, mod);
      ");
            recordDelegate = moduleRecordDelegate;

            return(JavaScriptValue.GlobalObject.GetProperty(modulesSymbol).GetProperty(specifier));
        }