0.8.0 • Published 3 years ago

@minthesize/futurism v0.8.0

Weekly downloads
209
License
MIT
Repository
github
Last release
3 years ago

Futurism

Twitter follow

All Contributors

Lazy-load Rails partials via CableReady

Facts

  • only one dependency: CableReady
  • bundle size (without CableReady) is around ~1.04kB

Usage

with a helper in your template

<%= futurize @posts %>

custom <futurism-element>s (in the form of a <div> or a <tr is="futurism-table-row"> are rendered. Those custom elements have an IntersectionObserver attached that will send a signed global id to an ActionCable channel (FuturismChannel) which will then replace the placeholders with the actual resource partial.

With that method, you could lazy load every class that has to_partial_path defined (ActiveModel has by default).

You can pass the placeholder as a block:

<%= futurize @posts, extends: :tr do %>
  <td class="placeholder"></td>
<% end %>

aa601dec1930151f71dbf0d6b02b61c9

Partial Path

Remember that you can override the partial path in you models, like so:

class Post < ApplicationRecord
  def to_partial_path
    "home/post"
  end
end

That way you get maximal flexibility when just specifying a single resource.

Installation

Add this line to your application's Gemfile:

gem 'futurism'

And then execute:

$ bundle

To copy over the javascript files to your application, run

$ bin/rails futurism:install

! Note that the installer will run yarn install @minthesize/futurism for you !

Manual Installation

After bundle, install the Javascript library:

$ bin/yarn install @minthesize/futurism

In your app/javascript/channels/index.js, add the following

import * as Futurism

import consumer from './consumer'

Futurism.initializeElements()
Futurism.createSubscription(consumer)

Contributing

License

The gem is available as open source under the terms of the MIT License.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

0.8.0

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

4 years ago

0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago