Wire, a reactive programming lib

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
italonascimento
Prole
Posts: 2
Joined: Thu Sep 21, 2017 2:35 am

Wire, a reactive programming lib

Post by italonascimento » Thu Sep 21, 2017 3:32 am

Hi everyone,

I'd like to present you Wire, a simple lib for reactive programming in LÖVE:
https://github.com/italonascimento/wire

It's still in early stage of development, but is already usable and documented, so I'd be happy to know what the community thinks of it.

For those who enjoy reactive programming, like myself, this lib aims to be a simple way to develop games in a reactive and declarative way, separating the logics from the side effects.

On the other hand, for those who are not familiarized with the reactive paradigm, it may seem overcomplicated at first, but hey, don't be scared!

Basicaly, a Wire powered game is written as a pure fuction, which receives sources and returns sinks. The sources table contains reactive streams of the user's intents, while the sinks table contains streams of side effects to be performed.

A basic example:

Code: Select all

local function game(sources)
  return {
    reducer = rx.Observable.merge(
      -- initial state
      rx.Observable.of(function()
        return {
          text = 'Hello World'
        })
      end),
      
      -- update state on key press
      sources.events.keypressed
        :filter(function(key)
          return key == 'space'
        end)
        :map(function()
          return function(prevState)
            return wire.assign(prevState, {
              text = 'Hello Interactive World :)'
            })
          end
        end)
    ),
    
    -- emit render on state update
    render = sources.state
      :map(function(state)
        return function()
          love.graphics.print(state.text, 8, 8)
        end
      end)
  }
end
On the above code we have a sinks table containing:
  • a reducer stream, which is a merge of two streams: one that emits right away, setting the game initial state to { text = 'Hello World' }, and a second one that emits everytime the user hits the space key, which sets the game state to { text = 'Hello Interactive World :)' };
  • and a render key, which emits a new render function everytime the game state is updated.
Running this code would print 'Hello World' on the screen, then print 'Hello Interactive World :)' after hitting space.

Want to know more about Wire's concept and usage? Take a look at the documentation:
https://italonascimento1.gitbooks.io/wire/content/

Feel free to make comments or to ask any questions!

User avatar
kicknbritt
Prole
Posts: 42
Joined: Sat May 30, 2015 2:15 am
Location: Chicago, IL

Re: Wire, a reactive programming lib

Post by kicknbritt » Fri Sep 22, 2017 10:03 am

This looks extremely interesting and I was quite interested in this sort of idea. Will definitely check this out when I get the time.
"I AM THE ARBITER!!!" *Pulls out Energy sword and kills everything*

italonascimento
Prole
Posts: 2
Joined: Thu Sep 21, 2017 2:35 am

Re: Wire, a reactive programming lib

Post by italonascimento » Fri Sep 22, 2017 6:50 pm

Nice! When the time has come, i'd like to know your impressions!

Post Reply

Who is online

Users browsing this forum: yetneverdone and 5 guests