pulumi/examples/vote50/app.js
joeduffy d6b2575008 Add a few lingering changes to the Mu voting example
Some of this is out of date, however I'm archiving work in progress,
and will freshen it up momentarily.
2016-11-01 10:31:21 -07:00

28 lines
834 B
JavaScript

var mu = require("mu");
// Define a Service that creates a Stack, wires up Functions to Triggers, and exposes an API:
class VotingService extends mu.Service {
constructor() {
super();
this.votes = new mu.services.Table();
this.voteCounts = new mu.services.Table();
this.votes.forEach(vote => {
// Keep our aggregated counts up-to-date:
this.voteCounts.updateIncrement(vote.color, vote.count);
});
}
vote(info) {
this.votes.push({ color: info.color, count: 1 });
}
}
// Create a HTTP endpoint Service that receives votes from an API:
var voteAPI = new mu.services.HTTPGateway();
for (var state of [ "AL", "AK", /*...,*/ "WI", "WY" ]) {
var votingService = new VotingService();
voteAPI.register(`/${state}/vote`, votingService);
}