Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memoization #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add memoization #4

wants to merge 1 commit into from

Conversation

hlascelles
Copy link
Owner

This adds memoization and tests.

This adds memoization and tests.
config.to_prepare do
ActiveSupport.on_load :action_controller do
include KnockoutAssetsHelper
helper_method :knockout_assets
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On reload, you presumably want to bust the knockout_assets cache - will that happen?

module KnockoutAssetsHelper
include ::Memery

memoize def knockout_assets(options = {})
options = {
exclude: nil,
preload: true,
include: /.*\.(png|gif|jpg|jpeg|bmp|svg)/,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these file extensions be anchored to the end of path as /.*\.(png|...|svg)$/?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you can probably drop the .* at the start

@@ -0,0 +1,7 @@
class ApplicationController < ActionController::Base
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on the above assets in the GH diff, but if this is a public gem, I don't think we should include other companies' logos

@@ -0,0 +1,2 @@
<%= knockout_assets %>
<% knockout_assets # Check calling it a second time is memoized %>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid to call it twice? Why/how does that happen? Should it be an error instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants