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

Emit 'load' events on Loader and Environment instances #1196

Merged
merged 1 commit into from Mar 5, 2019

Conversation

fdintino
Copy link
Collaborator

@fdintino fdintino commented Mar 4, 2019

Summary

Adds a 'load' event to Environment and Loader instances, to allow runtime dependency detection.

Closes #1153

Checklist

I've completed the checklist below to ensure I didn't forget anything. This makes reviewing this PR as easy as possible for the maintainers. And it gets this change released as soon as possible.

@codecov-io
Copy link

Codecov Report

Merging #1196 into master will decrease coverage by 0.13%.
The diff coverage is 64.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1196      +/-   ##
==========================================
- Coverage   89.94%   89.81%   -0.14%     
==========================================
  Files          22       22              
  Lines        2985     2995      +10     
==========================================
+ Hits         2685     2690       +5     
- Misses        300      305       +5
Impacted Files Coverage Δ
nunjucks/src/compiler.js 95.51% <100%> (ø) ⬆️
nunjucks/src/loader.js 100% <100%> (+27.27%) ⬆️
nunjucks/src/parser.js 93.85% <100%> (ø) ⬆️
nunjucks/src/nodes.js 72.5% <100%> (ø) ⬆️
nunjucks/src/web-loaders.js 85.71% <100%> (+0.42%) ⬆️
nunjucks/src/object.js 73.33% <44.44%> (-13.04%) ⬇️
nunjucks/src/environment.js 85.92% <55.55%> (-0.87%) ⬇️
nunjucks/src/node-loaders.js 71.42% <75%> (+1.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 057e7b3...45325bf. Read the comment docs.


The 'load' event gets emitted whenever a Loader retrieves the source of a
template. It can be listened to in order to determine template dependencies
at runtime. The arguments emitted to the callback are:

Choose a reason for hiding this comment

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

s/emitted/passed/

@@ -59,4 +60,26 @@ class Obj {
}
}

module.exports = Obj;
class EmitterObj extends EventEmitter {
Copy link

Choose a reason for hiding this comment

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

Probably not worth changing now, but other EventEmitters are available, e.g. little-emitter, which is smaller and doesn't require the addition or modification of a superclass:

const EventEmitter = require('little-emitter'); 

class Environment {
    constructor() {
        EventEmitter(this); // mix in `emit`, `on` etc.
    }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went with the default webpack events shim just because it's so widely used, it was easy, it's well documented, and it only added 1.5K gzipped to the minified builds.

@fdintino fdintino merged commit 1338712 into master Mar 5, 2019
@fdintino fdintino deleted the pr-emit-load-events branch March 5, 2019 08:29
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.

Provide a way to discover a template's dependencies
3 participants