0.0.24 • Published 9 months ago

@sbrew.com/atv v0.0.24

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

atv-sm

atv.js

Lightweight JavaScript for Rails inspired by Stimulus.js

Do you just want to have actions, targets, and values available in your Rails JS controllers? Tired of messing around with this and bind and the other bad parts of JavaScript?

Do you want to not care about whether you have underscores or dashes in your Rails JS data attributes in the HTML?

Is stimulus just not DRY enough for you?

If so, this library might be for you!

Here is an example that simulates a conversation you might have upon meeting an extraterrestrial alien:

<!-- greeting.html -->

<div data-atv-controller="greeting" data-atv-greeting-values="<%= {greeting: 'We come in peace!'}.to_json %>">
  <p>Hello earthling!</p>
  <button data-atv-greeting-action="click">Greet me</button>
  <p data-atv-greeting-target="output"></p>
</div>

For the controller, all you need to provide is an connect method that receives the targets, values, root element, and module as arguments. It needs to return a hash of action functions (which receive regular old DOM events).

  // app/javascript/controllers/greeting_atv.js
  const connect = (targets, values) => {
    const actions = {
      click: (actor) => {
        actor.style.display = 'none'; // the button
        targets.output.innerText = values.greeting; // the output paragraph
      }
    }
    return actions;
  };

  export { connect };

Finally, the following JS is required (typically in the application layout header) to activate it on your page

  import { activate } from 'atv';

  activate();

Compare this to the stimulus equivalent: in particular the "action" declaration. Also note that in stimulus it is darn near impossible to use it at all without JavaScript "classes". With ATV you can use those if you want, but you don't have to.

Examples

ATV By Example

Coming Soon!

  • More documentation!
  • Tests (right now I'm leveraging another private project for this)
  • And other things

Contributing

ATV is still a very young project. This incarnation started afresh in August 2024 after a couple of previous sketches and prototypes were thrown out.

If you like this idea and want to help out please join or start a discussion here on the GitHub page. I'm looking for like minded rails fans who also are striving to do clean, minimalist JavaScript along the lines of Douglas Crockford (JavaScript--The Good Parts).

0.0.23

9 months ago

0.0.24

9 months ago

0.0.20

9 months ago

0.0.21

9 months ago

0.0.22

9 months ago

0.0.14

10 months ago

0.0.15

9 months ago

0.0.16

9 months ago

0.0.17

9 months ago

0.0.18

9 months ago

0.0.19

9 months ago

0.0.10

10 months ago

0.0.11

10 months ago

0.0.12

10 months ago

0.0.13

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago