arqex / freezer

A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
MIT License
1.28k stars 56 forks source link

Make Freezer usable with strict Content Security Policy #100

Closed greghuc closed 7 years ago

greghuc commented 7 years ago

Hi there,

This is a small PR to ensure Freezer can be used with a strict Content Security Policy. At present, it cannot, because of a line in utils.js that evals a string: var global = (new Function("return this")());.

I fixed this by replacing the line with the same functionality as used by Browserify:

var global = typeof global !== 'undefined' ? 
             global : 
             typeof self !== 'undefined' ? 
               self : 
               typeof window !== 'undefined' ?
               window :
               {};

For background, you can read a detailed discussion of how to get the global Javascript object here: https://www.contentful.com/blog/2017/01/17/the-global-object-in-javascript/

And browserify's use of this approach is here: https://github.com/substack/insert-module-globals/blob/769f4bd08e01b77a620f2e2de1d2249c8311b0a2/index.js#L30

Many thanks for such a beautiful library!

Greg

greghuc commented 7 years ago

@dantman I changed the indentation to match the rest of the file.

arqex commented 7 years ago

Thanks for noticing it @greghuc, nice catch! Also thanks for the make it pretty @dantman

I'll merge this for the next version