Skip to content

Instantly share code, notes, and snippets.

View andreasronge's full-sized avatar

Andreas Ronge andreasronge

View GitHub Profile
defmodule Game do
defstruct board: nil, my_position: nil, name: "", health: 0
end
defmodule Board do
defstruct positions: %{}, width: 0, height: 0
end
defmodule Snake do
defstruct id: "", positions: %{}
@andreasronge
andreasronge / README.md
Last active October 27, 2015 18:44
Trying to improve redux architecture - cohesion and state context

Redux-Context

Notice No implementation exist yet, see Readme Driven Development

The problem:

  • Bad cohesion - in a typical redux application it's difficult to understand how it works since it consists of many small (good !) related functions spread out in many different files and folders.
  • Bad isolation - many functions (redux's actions and react-redux's connect) uses the global redux state object. Only reducers works on subtrees of the state tree.
  • Too many level of indirections - React props referencing redux state via mapStateToProps functions, reducers references actions via strings, async action creators references redux state.
require 'neo4j/tasks/neo4j_server'
# Lets find me:
me = Human.where(name: 'andreas').first
# And my posh cat:
dutchess = me.pets.where(character: 'posh').first
# And find all cat owners that have a posh cat mummy:
Cat.as(:c).where("c.character='posh'").kittens(:k).owner.first # => me
class Cat < Animal
property :name
has_many :out, :kittens, type: :kittens, model_class: self
has_one :in, :mother, origin: :kittens, model_class: self
end
class Animal
include Neo4j::ActiveNode
has_one :in, :owner, origin: :pets, model_class: Human
end
require 'neo4j'
Neo4j::Session.open
class Human
include Neo4j::ActiveNode
property :name
# A human can have outgoing relationships of type pets to animals
# The name of the generated accessor method will be the same as the relationship type: pets
has_many :out, :pets, type: :pets, model_class: :Animal
end
cats = Neo4j::Session.query.match('(h:Human)-[:pets]->(p)').where(h: {name: 'andreas'}).pluck(:p)
# print the name of the cats
puts cats[0][:name]
puts cats[1][:name]
# Create a node with on property name='andreas', and one label 'Human'
andreas = Neo4j::Node.create({name: 'andreas'}, :Human)
duchess = Neo4j::Node.create({name: 'duchess', character: 'posh'}, :Animal, :Cat)
kim = Neo4j::Node.create({name: 'kim', age: 1}, :Animal, :Cat)
# Create a relationship of type pets between andreas and duchess
# Relationships can also have properties
andreas.create_rel(:pets, duchess, since: 2014)
andreas.create_rel(:pets, kim, since: 2014)
duchess.create_rel(:kittens, kim)