Skip to content

Commit

Permalink
eliminate shells/lib/utils/js in favor of runtime/runtime.js (Pol…
Browse files Browse the repository at this point in the history
…ymerLabs#3980)

* eliminate `shells/lib/utils/js` in favor of `runtime/runtime.js`

* s/resolve/resolveRecipe

* simplify expression

* fix typos

* addressing comments
  • Loading branch information
Scott J. Miles authored Nov 14, 2019
1 parent cc1e183 commit 0e7ce96
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 219 deletions.
4 changes: 2 additions & 2 deletions shells/dev-shell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import {pecIndustry} from '../../build/platform/pec-industry-web.js';
import {RecipeResolver} from '../../build/runtime/recipe/recipe-resolver.js';
import {StorageProviderFactory} from '../../build/runtime/storage/storage-provider-factory.js';
import {devtoolsArcInspectorFactory} from '../../build/devtools-connector/devtools-arc-inspector.js';
import {Utils} from '../lib/utils.js';
import {UiSlotComposer} from '../../build/runtime/ui-slot-composer.js';
import {SlotObserver} from '../lib/xen-renderer.js';

import '../../build/services/ml5-service.js';
import '../../build/services/random-service.js';

const root = '../..';
const urlMap = Runtime.mapFromRootPath(root);

// import DOM node references
const {
Expand Down Expand Up @@ -103,7 +103,7 @@ async function wrappedExecute() {
document.dispatchEvent(new Event('clear-arcs-explorer'));
outputPane.reset();

const loader = new Loader(Utils.createPathMap(root), filePane.getFileMap());
const loader = new Loader(urlMap, filePane.getFileMap());
// TODO(sjmiles): should be a static method
loader.flushCaches();

Expand Down
1 change: 1 addition & 0 deletions shells/diagnostic/user-context/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>

<script type="module" src='../../lib/firebase-support.js'></script>
<script type="module" src="index.js"></script>

<style>
Expand Down
10 changes: 3 additions & 7 deletions shells/diagnostic/user-context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
import '../../lib/firebase-support.js';
import '../../lib/platform/loglevel-web.js';
import {Runtime} from '../../../build/runtime/runtime.js';
import {Const} from '../../configuration/constants.js';
import {Utils} from '../../lib/utils.js';
import {SyntheticStores} from '../../lib/synthetic-stores.js';
import {StoreObserver} from '../../lib/store-observer.js';
import {ArcHandleListener, ArcMetaListener, ProfileListener, ShareListener} from '../../lib/context-listeners.js';
Expand All @@ -20,18 +19,15 @@ import '../../../modalities/dom/components/arc-tools/store-explorer.js';
const storage = `firebase://arcs-storage.firebaseio.com/AIzaSyBme42moeI-2k8WgXh-6YK_wYyjEXo4Oz8/0_7_0/sjmiles`;

// configure arcs environment
const paths = {
root: '../../..'
};
Utils.init(paths.root, paths.map);
Runtime.init('../../../');

let context;
let UserObserverImpl;

const observe = async () => {
// prepare context
if (!context) {
context = await Utils.parse('');
context = await Runtime.parse('');
//
const ArcHandleListenerImpl = ArcHandleDisplayMixin(ArcHandleListener);
//
Expand Down
10 changes: 5 additions & 5 deletions shells/lib/components/arc-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import {ArcType} from '../../../build/runtime/type.js';
import {logsFactory} from '../../../build/platform/logs-factory.js';
import {Runtime} from '../../../build/runtime/runtime.js';
import {SyntheticStores} from '../synthetic-stores.js';
import {Utils} from '../utils.js';

const {log, warn, error} = logsFactory('ArcHost', '#cade57');

Expand All @@ -32,7 +32,7 @@ export class ArcHost {
async spawn(config) {
log('spawning arc', config);
this.config = config;
const context = this.context || await Utils.parse(``);
const context = this.context || await Runtime.parse(``);
const storage = config.storage || this.storage;
this.serialization = await this.computeSerialization(config, storage);
this.arc = await this._spawn(context, this.composer, storage, config.id, this.serialization, this.portFactories);
Expand Down Expand Up @@ -71,14 +71,14 @@ export class ArcHost {
return serialization;
}
async _spawn(context, composer, storage, id, serialization, portFactories) {
return await Utils.spawn({id, context, composer, serialization, storage: `${storage}/${id}`, portFactories});
return await Runtime.spawnArc({id, context, composer, serialization, storage: `${storage}/${id}`, portFactories});
}
async instantiateDefaultRecipe(arc, manifest) {
log('instantiateDefaultRecipe');
try {
manifest = await Utils.parse(manifest);
manifest = await Runtime.parse(manifest);
const recipe = manifest.allRecipes[0];
const plan = await Utils.resolve(arc, recipe);
const plan = await Runtime.resolveRecipe(arc, recipe);
if (plan) {
await this.instantiatePlan(arc, plan);
}
Expand Down
129 changes: 0 additions & 129 deletions shells/lib/utils.js

This file was deleted.

4 changes: 2 additions & 2 deletions shells/pipes-shell/source/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* http://polymer.github.io/PATENTS.txt
*/

import {Utils} from '../../lib/utils.js';
import {Runtime} from '../../../build/runtime/runtime.js';

export const requireContext = async manifest => {
if (!requireContext.promise) {
requireContext.promise = Utils.parse(manifest);
requireContext.promise = Runtime.parse(manifest);
window.context = await requireContext.promise;
}
return await requireContext.promise;
Expand Down
4 changes: 2 additions & 2 deletions shells/pipes-shell/source/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import {Type} from '../../../../build/runtime/type.js';
import {Utils} from '../../../lib/utils.js';
import {Runtime} from '../../../../build/runtime/runtime.js';
import {Schemas} from '../schemas.js';

export const conformType = type => {
Expand All @@ -33,7 +33,7 @@ export const recipeByName = (manifest, name) => {
};

export const instantiateRecipe = async (arc, recipe) => {
const plan = await Utils.resolve(arc, recipe);
const plan = await Runtime.resolveRecipe(arc, recipe);
if (plan) {
await arc.instantiate(plan);
return plan;
Expand Down
8 changes: 2 additions & 6 deletions shells/pipes-shell/source/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import {logsFactory} from '../../../build/platform/logs-factory.js';
import {Runtime} from '../../../build/runtime/runtime.js';
import {UiSlotComposer} from '../../../build/runtime/ui-slot-composer.js';
import {Utils} from '../../lib/utils.js';
import {pec} from './verbs/pec.js';
import {runArc, stopArc, uiEvent} from './verbs/run-arc.js';
import {event} from './verbs/event.js';
Expand All @@ -35,13 +34,10 @@ export const busReady = async (bus, {manifest}) => {
};

const configureRuntime = async ({rootPath, urlMap, storage, manifest}, bus) => {
// configure arcs environment
Utils.init(rootPath, urlMap);
// configure arcs runtime environment
Runtime.init(rootPath, urlMap);
// marshal context
const context = await requireContext(manifest || config.manifest);
// configure Runtime
const runtime = new Runtime(Utils.env.loader, UiSlotComposer, context);
runtime.pecFactory = Utils.env.pecFactory;
// attach verb-handlers to dispatcher
populateDispatcher(dispatcher, storage, context);
// send pipe identifiers to client
Expand Down
6 changes: 3 additions & 3 deletions shells/pipes-shell/source/verbs/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* http://polymer.github.io/PATENTS.txt
*/

import {Utils} from '../../../lib/utils.js';
import {Runtime} from '../../../build/runtime/runtime.js';
import {logsFactory} from '../../../../build/platform/logs-factory.js';

const {log} = logsFactory('pipe::parse');
Expand All @@ -19,10 +19,10 @@ export const parse = async ({path, content}, tid, bus) => {
let manifest;
if (path) {
log(`loading [${path}]`);
manifest = await Utils.parseFile(path);
manifest = await Runtime.parseFile(path);
} else if (content) {
log(`parsing [${content.length}] bytes`);
manifest = await Utils.parse(content);
manifest = await Runtime.parse(content);
}
let recipes = [];
if (manifest) {
Expand Down
12 changes: 6 additions & 6 deletions shells/pipes-shell/source/verbs/run-arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import {logsFactory} from '../../../../build/platform/logs-factory.js';
import {RecipeUtil} from '../../../../build/runtime/recipe/recipe-util.js';
import {devtoolsArcInspectorFactory} from '../../../../build/devtools-connector/devtools-arc-inspector.js';
import {Utils} from '../../../lib/utils.js';
import {Runtime} from '../../../../build/runtime/runtime.js';
import {portIndustry} from '../pec-port.js';

const {log, warn} = logsFactory('pipe');
Expand All @@ -29,10 +29,10 @@ export const runArc = async (msg, bus, runtime) => {
return null;
}
const arc = runtime.runArc(arcId, storageKeyPrefix || 'volatile://', {
fileName: './serialized.manifest',
pecFactories: [].concat([runtime.pecFactory], [portIndustry(bus, pecId)]),
loader: runtime.loader,
inspectorFactory: devtoolsArcInspectorFactory,
fileName: './serialized.manifest',
pecFactories: [runtime.pecFactory, portIndustry(bus, pecId)],
loader: runtime.loader,
inspectorFactory: devtoolsArcInspectorFactory
});
arc.pec.slotComposer.slotObserver = {
observe: (content, arc) => {
Expand All @@ -50,7 +50,7 @@ export const runArc = async (msg, bus, runtime) => {
};

const instantiateRecipe = async (arc, recipe, particles) => {
let plan = await Utils.resolve(arc, recipe);
let plan = await Runtime.resolveRecipe(arc, recipe);
if (!plan) {
warn(`failed to resolve recipe ${recipe}`);
return false;
Expand Down
6 changes: 2 additions & 4 deletions shells/pipes-shell/source/verbs/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import {generateId} from '../../../../modalities/dom/components/generate-id.js';
import {Utils} from '../../../lib/utils.js';
import {Runtime} from '../../../../build/runtime/runtime.js';
import {recipeByName, instantiateRecipe} from '../lib/utils.js';
import {portIndustry} from '../pec-port.js';
import {logsFactory} from '../../../../build/platform/logs-factory.js';
Expand All @@ -23,15 +23,13 @@ export const spawn = async ({modality, recipe}, tid, bus, composerFactory, stora
return null;
} else {
// instantiate arc
const arc = await Utils.spawn({
const arc = await Runtime.spawnArc({
context,
//storage,
id: generateId(),
composer: composerFactory(modality, bus, tid),
portFactories: [portIndustry(bus)]
});
// TODO(sjmiles): why is this here?
//arc.tid = tid;
if (contextRecipe) {
// instantiate optional recipe
await instantiateRecipe(arc, contextRecipe);
Expand Down
6 changes: 3 additions & 3 deletions shells/planner-shell/planner-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import './config.js';

// platform agnostic code
import {DevtoolsConnection} from '../../build/devtools-connector/devtools-connection.js';
import {Utils} from '../lib/utils.js';
import {Runtime} from '../../build/runtime/runtime.js';
import {ArcHost} from '../lib/components/arc-host.js';
import {RamSlotComposer} from '../lib/components/ram-slot-composer.js';
import {Const} from '../configuration/constants.js';
Expand Down Expand Up @@ -46,11 +46,11 @@ export class PlannerShellInterface {
// connect to DevTools if running with --explore
await maybeConnectToDevTools();
// create an arcs environment
Utils.init(assetsPath);
Runtime.init(assetsPath);
// observe user's arc list
const userArcs = new UserArcs(storage, userid);
// base context (particles & recipes) from static manifest
const context = await Utils.parse(contextManifest);
const context = await Runtime.parse(contextManifest);
// userContext continually updates context based on user's arcs
const userContext = new UserContext();
// wait for context to spin up
Expand Down
Loading

0 comments on commit 0e7ce96

Please sign in to comment.