Skip to content

Instantly share code, notes, and snippets.

@distributedlife
Last active September 20, 2016 09:09
Show Gist options
  • Save distributedlife/1ed65344ef2b31808588c0f3431aabf0 to your computer and use it in GitHub Desktop.
Save distributedlife/1ed65344ef2b31808588c0f3431aabf0 to your computer and use it in GitHub Desktop.
a very small ensemble demo
import define from 'ensemblejs/lib/define';
import { on } from 'ensemblejs/lib';
const bel = require('bel');
define('StateSeed', () => ({
game: {
space: 0,
continuous: 0,
}
}));
const increment = (current) => current + 1;
const upSpaceYourFace = () => [`game.space`, increment];
const incrementContinuous = () => [`game.continuous`, increment];
define('ActionMap', () => ({ space: [{ call: upSpaceYourFace, onRelease: true }] }));
on('PhysicsFrame', () => incrementContinuous);
const overlay = () => bel`
<div>
<div id="space" class="space">0</div>
<div id="continuous" class="continuous">0</div>
</div>
`;
const setOnElement = (id, value) => (document.getElementById(id) && (document.getElementById(id).textContent = value));
const updateSpace = (current) => setOnElement('space', current);
const updateContinuous = (current) => setOnElement('continuous', current);
define('OnClientReady', ['StateTracker'], (tracker) => {
document.getElementById('overlay').appendChild(overlay());
return () => {
tracker().onChangeOf(`game.space`, updateSpace);
tracker().onChangeOf(`game.continuous`, updateContinuous);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment