Skip to content

Instantly share code, notes, and snippets.

View MarcoWorms's full-sized avatar
:shipit:
undefined

Marco Guaspari Worms MarcoWorms

:shipit:
undefined
View GitHub Profile
// --------------------------------------------------------
// "No javascript qualquer variável pode ser uma função ou o resultado de uma função"
function umaFuncao () {
console.log('faz coisas aqui dentro')
return 'e sempre deveria retornar alguma coisa'
}
const funcao = umaFuncao
function renderState (state) {
var html = '<p>' + state.something + '</p>'
document.getElementById('root').innerHTML = html
}
function createStore() {
var state = {
something: "olá mundo"
}
renderState(state)
function renderState (state) {
var html = '<p>' + state.something + '</p>'
document.getElementById('root').innerHTML = html
}
function createStore() {
var state = {
something: "olá mundo"
}
renderState(state)
function renderState (state) {
var html = '<p>' + state.something + '</p>'
document.getElementById('root').innerHTML = html
}
@MarcoWorms
MarcoWorms / main.js
Last active November 30, 2016 20:31
function createStore() {
var state = {}
return {
getState: function () {
return state
},
setState: function (newState) {
state = newState
}
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<div id="root"></div>
<script src="main.js"></script>
</body>
</html>
@MarcoWorms
MarcoWorms / mini-redux.js
Last active June 3, 2024 04:42
Redux in a nutshell
function createStore (reducers) {
var state = reducers()
const store = {
dispatch: (action) => {
state = reducers(state, action)
},
getState: () => {
return state
}
}
const Immutable = require('immutable')
const add = (channels, name) => {
return channels.set(name, Immutable.List())
}
const addAction = (channels, name, action) => {
return channels.set(name, channels.get(name).push(action))
}
//
// Motivations:
//
// * bring accessible functional programming to game development
// * handy and easy default options for quick game prototyping
// * flexibility for advanced game developers
const W = {
getAngle: (pointA, pointB) => null,
emit: (channel, message, data) => null
// example of what this code would produce => http://worms.io/pocDeclarative
const makePlayer = () => {
return {
initial: {
size: [50, 50],
position: [10, 10],
physics: true
},