Skip to content

Instantly share code, notes, and snippets.

@sethvincent
Last active January 20, 2016 06:51
Show Gist options
  • Save sethvincent/bc851c615a173b4de782 to your computer and use it in GitHub Desktop.
Save sethvincent/bc851c615a173b4de782 to your computer and use it in GitHub Desktop.
an idea for a redux-like module for managing the state of a game

gamestate

Manage the state of JavaScript games using unidirectional data flow.

Usage

var createGame = require('gamestate')

var game = createGame(document.body, {
  context: 'webgl'
})

function modifier (action, state) {
  if (action.type === 'message') {
    return { message: action.message }
  }
}

var render = game.start(modifier, {
  message: 'this is the initial game state'
})

render(function (ctx, state) {
  // render the game
  console.log(state.message)
})

game.update({
  type: 'message',
  message: 'state has changed'
})

Unanswered questions

I'd like to manage game state and ui state (using virtual-dom) in compatible ways. How might that be simplified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment