android:JSLoader move to JSLoaderManager,not hold by DoricRegistry

This commit is contained in:
pengfei.zhou 2020-01-10 15:02:13 +08:00 committed by osborn
parent b9a2065f8a
commit d4b19eb4ea
2 changed files with 16 additions and 19 deletions

View File

@ -17,9 +17,6 @@ package pub.doric;
import android.text.TextUtils; import android.text.TextUtils;
import pub.doric.loader.DoricAssetJSLoader;
import pub.doric.loader.DoricHttpJSLoader;
import pub.doric.loader.IDoricJSLoader;
import pub.doric.plugin.AnimatePlugin; import pub.doric.plugin.AnimatePlugin;
import pub.doric.plugin.NavBarPlugin; import pub.doric.plugin.NavBarPlugin;
import pub.doric.plugin.NavigatorPlugin; import pub.doric.plugin.NavigatorPlugin;
@ -50,7 +47,6 @@ import pub.doric.utils.DoricMetaInfo;
import pub.doric.plugin.DoricJavaPlugin; import pub.doric.plugin.DoricJavaPlugin;
import pub.doric.plugin.ModalPlugin; import pub.doric.plugin.ModalPlugin;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -65,14 +61,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class DoricRegistry { public class DoricRegistry {
private static Map<String, String> bundles = new ConcurrentHashMap<>(); private static Map<String, String> bundles = new ConcurrentHashMap<>();
private static Set<DoricLibrary> doricLibraries = new HashSet<>(); private static Set<DoricLibrary> doricLibraries = new HashSet<>();
private static Set<IDoricJSLoader> jsLoaders = new HashSet<>();
private Map<String, Object> extendedEnvValues = new HashMap<>(); private Map<String, Object> extendedEnvValues = new HashMap<>();
static {
addJSLoader(new DoricAssetJSLoader());
addJSLoader(new DoricHttpJSLoader());
}
private Map<String, DoricMetaInfo<DoricJavaPlugin>> pluginInfoMap = new HashMap<>(); private Map<String, DoricMetaInfo<DoricJavaPlugin>> pluginInfoMap = new HashMap<>();
private Map<String, DoricMetaInfo<ViewNode>> nodeInfoMap = new HashMap<>(); private Map<String, DoricMetaInfo<ViewNode>> nodeInfoMap = new HashMap<>();
@ -148,13 +138,6 @@ public class DoricRegistry {
return bundles.get(name); return bundles.get(name);
} }
public static void addJSLoader(IDoricJSLoader jsLoader) {
jsLoaders.add(jsLoader);
}
public static Collection<IDoricJSLoader> getJSLoaders() {
return jsLoaders;
}
public void setEnvironmentVariabel(String key, Object val) { public void setEnvironmentVariabel(String key, Object val) {
extendedEnvValues.put(key, val); extendedEnvValues.put(key, val);

View File

@ -17,8 +17,9 @@ package pub.doric.loader;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import pub.doric.DoricRegistry;
import pub.doric.async.AsyncResult; import pub.doric.async.AsyncResult;
/** /**
@ -27,19 +28,32 @@ import pub.doric.async.AsyncResult;
* @CreateDate: 2019-11-23 * @CreateDate: 2019-11-23
*/ */
public class DoricJSLoaderManager { public class DoricJSLoaderManager {
private Set<IDoricJSLoader> jsLoaders = new HashSet<>();
private DoricJSLoaderManager() { private DoricJSLoaderManager() {
addJSLoader(new DoricAssetJSLoader());
addJSLoader(new DoricHttpJSLoader());
} }
private static class Inner { private static class Inner {
private static final DoricJSLoaderManager sInstance = new DoricJSLoaderManager(); private static final DoricJSLoaderManager sInstance = new DoricJSLoaderManager();
} }
public void addJSLoader(IDoricJSLoader jsLoader) {
jsLoaders.add(jsLoader);
}
private Collection<IDoricJSLoader> getJSLoaders() {
return jsLoaders;
}
public static DoricJSLoaderManager getInstance() { public static DoricJSLoaderManager getInstance() {
return Inner.sInstance; return Inner.sInstance;
} }
public AsyncResult<String> loadJSBundle(String scheme) { public AsyncResult<String> loadJSBundle(String scheme) {
Collection<IDoricJSLoader> jsLoaders = DoricRegistry.getJSLoaders(); Collection<IDoricJSLoader> jsLoaders = getJSLoaders();
for (IDoricJSLoader jsLoader : jsLoaders) { for (IDoricJSLoader jsLoader : jsLoaders) {
if (jsLoader.filter(scheme)) { if (jsLoader.filter(scheme)) {
return jsLoader.request(scheme); return jsLoader.request(scheme);