Experimental JS library with Rails

Hi everyone on this list. First time posting here :wink:

I’m writing here because I had an idea while working on a project that required heavy use of javascript and I thought I would share it with the world. Before I explain it, I would like to take a second to warn you that this library might feel very controversial to some of you because it goes against the grain when it comes to what’s available in terms of JS frameworks.

This small library is very early on and is very opinionated. Even so, here’s a few things that this library does.

Javascript objects are bound to DOM element

I may start with the most controversial feature. I know that prototype.js had issue with this a while ago. But the web environment is not what it’s used to be.

Event based response when dealing with JS request.

I wanted to have something that could use rails’ remote=true attributes and be automatically dispatch the response to different object in the DOM. So I build a custom XHR object that will take the response from JS and build an event with the following naming scheme: “controller:action”. So basically, if you send a form with remote=true to create a new posts through the PostsController, an event posts:create would be fired automatically.

Automatic instantiation of objects

Using the new DOM Observer pattern, it looks for any DOM object that declares a javascript object and instantiate it automatically. If the callback is defined in the object, the loaded callback is fired which allow someone to bind events to that object as soon as it’s ready.

Bind HTML to JavaScript events

HTML might be slower than JSON to render, but it offers a lot more flexibility. You can look for attributes, children, etc.

I’m aware that this might all sound a little vague, so I made a gem that, hopefully, will make it easier for you guys to understand.


Feel free to ask question if you have any :slight_smile: