Skip to content

Commit

Permalink
Start work on demo flow test.
Browse files Browse the repository at this point in the history
Rename "Suggestion" to "RecipeComponent"
  • Loading branch information
shans authored and dstoc committed Mar 7, 2017
1 parent 851db0d commit 19d30d8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 22 deletions.
28 changes: 14 additions & 14 deletions runtime/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Connection {
}
}

class Suggestion {
class RecipeComponent {
constructor(particleName, connections) {
this.particleName = particleName;
this.connections = connections;
Expand All @@ -42,37 +42,37 @@ class Suggestion {
}

class Recipe {
constructor(...suggestions) {
this.suggestions = suggestions;
constructor(...components) {
this.components = components;
}

instantiate(arc) {
this.suggestions.forEach(suggestion => suggestion.instantiate(arc));
this.components.forEach(component => component.instantiate(arc));
}
}

class RecipeBuilder {
constructor() {
this.suggestions = [];
this.currentSuggestion = undefined;
this.components = [];
this.currentComponent = undefined;
}
suggest(particleName) {
if (this.currentSuggestion !== undefined) {
this.suggestions.push(new Suggestion(this.currentSuggestion.name, this.currentSuggestion.connections));
if (this.currentComponent !== undefined) {
this.components.push(new RecipeComponent(this.currentComponent.name, this.currentComponent.connections));
}
this.currentSuggestion = {name: particleName, connections: []};
this.currentComponent = {name: particleName, connections: []};
return this;
}
connect(name, view) {
this.currentSuggestion.connections.push(new Connection(name, view));
this.currentComponent.connections.push(new Connection(name, view));
return this;
}
build() {
if (this.currentSuggestion !== undefined) {
this.suggestions.push(new Suggestion(this.currentSuggestion.name, this.currentSuggestion.connections));
if (this.currentComponent !== undefined) {
this.components.push(new RecipeComponent(this.currentComponent.name, this.currentComponent.connections));
}
return new Recipe(...this.suggestions)
return new Recipe(...this.components)
}
}

module.exports = { Recipe, Suggestion, Connection, RecipeBuilder }
module.exports = { Recipe, RecipeComponent, Connection, RecipeBuilder }
12 changes: 6 additions & 6 deletions runtime/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ var data = require('./data-layer.js');
class Resolver {

resolve(recipe, context) {
for (var suggestion of recipe.suggestions)
this.resolveSuggestion(suggestion, context);
for (var component of recipe.components)
this.resolveComponent(component, context);
}

resolveSuggestion(suggestion, context) {
for (var connection of suggestion.connections)
this.resolveConnection(suggestion, connection, context);
resolveComponent(component, context) {
for (var connection of component.connections)
this.resolveConnection(component, connection, context);
}

resolveConnection(suggestion, connection, context) {
resolveConnection(component, connection, context) {
// connection already has a view
if (connection.view !== undefined)
return;
Expand Down
47 changes: 47 additions & 0 deletions runtime/test/demo-flow-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license
* Copyright (c) 2017 Google Inc. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* Code distributed by Google as part of this project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/

var data = require("../data-layer.js");
var Arc = require("../arc.js");

class Person extends data.Entity {
constructor(name) {
super();
this._data = {name};
}

get data() { return this._data; }
}
Person.type = data.internals.Type.generate();

class Product extends data.Entity {
constructor(name) {
super();
this._data = {name};
}

get data() { return this._data; }
}
Product.type = data.internals.Type.generate();

function prepareExtensionArc() {
var arc = new Arc();
var personView = data.internals.viewFor(Person.type);
var productView = data.internals.viewFor(Product.type);
arc.addView(personView);
arc.addView(productView);
data.internals.commit([new Person("Claire"), new Product("Tea Pot"), new Product("Bee Hive"), new Product("Denim Jeans")])
}

describe('demo flow', function() {
it('flows like a demo', function() {
prepareExtensionArc();
});
});
4 changes: 2 additions & 2 deletions runtime/test/suggestinator-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe('suggestinator', function() {
var results = suggestinator.suggestinate(new Arc());
assert.equal(results[0].rank, 0.6);
assert.equal(results[1].rank, 1.8);
assert.equal(results[0].suggestions[0].particleName, "TwoInputTestParticle");
assert.equal(results[1].suggestions[0].particleName, "TestParticle");
assert.equal(results[0].components[0].particleName, "TwoInputTestParticle");
assert.equal(results[1].components[0].particleName, "TestParticle");
});

});

0 comments on commit 19d30d8

Please sign in to comment.