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

Possible global scope issue? #56

Open
nroose opened this issue Sep 22, 2016 · 2 comments
Open

Possible global scope issue? #56

nroose opened this issue Sep 22, 2016 · 2 comments

Comments

@nroose
Copy link

nroose commented Sep 22, 2016

I have one template inadvertently calling the Skim.withContext method of another template. It seems as though this should not happen, but it very definitely is. Any chance the call to Skim.withContext can be changed to be more specific? I have many templates and it's only happening with these two.

@svicalifornia
Copy link
Collaborator

@nroose Yes, the default behavior is to include the Skim preamble at the top of each compiled template. The preamble defines Skim as a global variable, and each template redefines this object, so all Skim templates will use the Skim object defined by the last template loaded.

Skim.withContext shouldn't rely on or alter any context specific to its enclosing template, so in theory it shouldn't matter which template defined it. Please let me know what side effects you're seeing so we can investigate further. (If you prefer, you can PM me via the email address on my GitHub profile.)

To avoid redefining the Skim preamble in each template, you can set the use_asset option in your Ruby code after loading the gem:

Skim::Engine.default_options[:use_asset] = true

Then you can add the Skim preamble manually to any JS file in a Sprockets asset pipeline:

//= require skim

@nroose
Copy link
Author

nroose commented Sep 29, 2016

I guess it's easier if I post part of the error message:

      TypeError: Requested keys of a value that is not an object.
      TypeError: Requested keys of a value that is not an object.
          at http://vm2.repairpal.com:3001/assets/reservations/backbone/templates/discounts_template.js?body=1:79
          at http://vm2.repairpal.com:3001/assets/reservations/backbone/templates/years_select_template.js?body=1:68
          at http://vm2.repairpal.com:3001/assets/reservations/backbone/templates/discounts_template.js?body=1:97
          at http://vm2.repairpal.com:3001/assets/reservations/backbone/views/discounts.js?body=1:18

Seems to me that the templates shouldn't call eachother, no? What's the rational for using global scope for these functions?

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

No branches or pull requests

2 participants