Bundle the default plugins together (#621)

We manually import the set of plugins to be used by the app in a few
different places. That's a bad smell. This commit creates a centralized
import point instead.

Test plan: `yarn test`
This commit is contained in:
Dandelion Mané 2018-08-07 15:53:20 -07:00 committed by GitHub
parent 0cf5923bce
commit 123b85146e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -14,10 +14,7 @@ import {type EdgeEvaluator} from "../../core/attribution/pagerank";
import {byEdgeType, byNodeType} from "./edgeWeights"; import {byEdgeType, byNodeType} from "./edgeWeights";
import * as MapUtil from "../../util/map"; import * as MapUtil from "../../util/map";
import * as NullUtil from "../../util/null"; import * as NullUtil from "../../util/null";
import {defaultStaticAdapters} from "../defaultPlugins";
import type {StaticPluginAdapter} from "../pluginAdapter";
import {StaticPluginAdapter as GithubAdapter} from "../../plugins/github/pluginAdapter";
import {StaticPluginAdapter as GitAdapter} from "../../plugins/git/pluginAdapter";
type Props = {| type Props = {|
+localStore: LocalStore, +localStore: LocalStore,
@ -27,14 +24,10 @@ type Props = {|
type EdgeWeights = Map<EdgeAddressT, UserEdgeWeight>; type EdgeWeights = Map<EdgeAddressT, UserEdgeWeight>;
type UserEdgeWeight = {|+logWeight: number, +directionality: number|}; type UserEdgeWeight = {|+logWeight: number, +directionality: number|};
const adapters = (): StaticPluginAdapter[] => {
return [new GithubAdapter(), new GitAdapter()];
};
const EDGE_WEIGHTS_KEY = "edgeWeights"; const EDGE_WEIGHTS_KEY = "edgeWeights";
const defaultEdgeWeights = (): EdgeWeights => { const defaultEdgeWeights = (): EdgeWeights => {
const result = new Map(); const result = new Map();
for (const adapter of adapters()) { for (const adapter of defaultStaticAdapters()) {
for (const {prefix} of adapter.edgeTypes()) { for (const {prefix} of adapter.edgeTypes()) {
result.set(prefix, {logWeight: 0, directionality: 0.5}); result.set(prefix, {logWeight: 0, directionality: 0.5});
} }
@ -47,7 +40,7 @@ type UserNodeWeight = number /* in log space */;
const NODE_WEIGHTS_KEY = "nodeWeights"; const NODE_WEIGHTS_KEY = "nodeWeights";
const defaultNodeWeights = (): NodeWeights => { const defaultNodeWeights = (): NodeWeights => {
const result = new Map(); const result = new Map();
for (const adapter of adapters()) { for (const adapter of defaultStaticAdapters()) {
for (const {prefix, defaultWeight} of adapter.nodeTypes()) { for (const {prefix, defaultWeight} of adapter.nodeTypes()) {
result.set(prefix, Math.log2(defaultWeight)); result.set(prefix, Math.log2(defaultWeight));
} }

View File

@ -13,8 +13,8 @@ import {
} from "../../core/attribution/pagerank"; } from "../../core/attribution/pagerank";
import type {DynamicPluginAdapter} from "../pluginAdapter"; import type {DynamicPluginAdapter} from "../pluginAdapter";
import {StaticPluginAdapter as GitAdapter} from "../../plugins/git/pluginAdapter";
import {StaticPluginAdapter as GithubAdapter} from "../../plugins/github/pluginAdapter"; import {defaultStaticAdapters} from "../defaultPlugins";
/* /*
This models the UI states of the credExplorer/App as a state machine. This models the UI states of the credExplorer/App as a state machine.
@ -250,7 +250,7 @@ export type GraphWithAdapters = {|
+adapters: $ReadOnlyArray<DynamicPluginAdapter>, +adapters: $ReadOnlyArray<DynamicPluginAdapter>,
|}; |};
export function loadGraphWithAdapters(repo: Repo): Promise<GraphWithAdapters> { export function loadGraphWithAdapters(repo: Repo): Promise<GraphWithAdapters> {
const statics = [new GitAdapter(), new GithubAdapter()]; const statics = defaultStaticAdapters();
return Promise.all(statics.map((a) => a.load(repo))).then((adapters) => { return Promise.all(statics.map((a) => a.load(repo))).then((adapters) => {
const graph = Graph.merge(adapters.map((x) => x.graph())); const graph = Graph.merge(adapters.map((x) => x.graph()));
return {graph, adapters}; return {graph, adapters};

View File

@ -0,0 +1,9 @@
// @flow
import type {StaticPluginAdapter} from "./pluginAdapter";
import {StaticPluginAdapter as GitAdapter} from "../plugins/git/pluginAdapter";
import {StaticPluginAdapter as GithubAdapter} from "../plugins/github/pluginAdapter";
export function defaultStaticAdapters(): $ReadOnlyArray<StaticPluginAdapter> {
return [new GitAdapter(), new GithubAdapter()];
}