Skip to content

Commit 5b7bfa3

Browse files
committed
feat(events): add PATTERNLAB_BUILD_END event and rename BUILD_START
Emitting PATTERNLAB_BUILD_END allows us to remove reliance on reloading liveServer on PATTERNLAB_PATTERN_CHANGE - which is too early
1 parent 18e74c2 commit 5b7bfa3

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

packages/core/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ const patternlab_module = function(config) {
132132
return Promise.resolve();
133133
});
134134
}
135+
})
136+
.then(() => {
137+
this.events.emit(events.PATTERNLAB_BUILD_END);
135138
});
136139
});
137140
}

packages/core/src/lib/buildPatterns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let pattern_exporter = new pe(); // eslint-disable-line
2525
const lineage_hunter = new lh();
2626

2727
module.exports = (deletePatternDir, patternlab, additionalData) => {
28-
patternlab.events.emit(events.PATTERNLAB_BUILD_PATTERN_START, patternlab);
28+
patternlab.events.emit(events.PATTERNLAB_BUILD_START, patternlab);
2929

3030
const paths = patternlab.config.paths;
3131

packages/core/src/lib/events.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ const EVENTS = Object.freeze({
1414
* @property {object} patternlab - global data store
1515
*
1616
*/
17-
PATTERNLAB_BUILD_PATTERN_START: 'patternlab-build-pattern-start',
17+
PATTERNLAB_BUILD_START: 'patternlab-build-start',
18+
19+
/**
20+
* @desc Emitted after all logic run inside `build()`, which is the entry point for single builds, pattern-only builds, run singly or when watched.
21+
* @property {object} patternlab - global data store
22+
*
23+
*/
24+
PATTERNLAB_BUILD_END: 'patternlab-build-end',
1825

1926
/**
2027
* @desc Emitted after patterns are iterated over to gather data about them. Right before Pattern Lab processes and renders patterns into HTML

packages/core/src/lib/server.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,8 @@ const server = patternlab => {
4545
);
4646

4747
const setupEventWatchers = () => {
48-
// watch for asset changes, and reload appropriately
49-
patternlab.events.on(events.PATTERNLAB_PATTERN_ASSET_CHANGE, data => {
50-
if (serverReady) {
51-
_module.reload(data);
52-
}
53-
});
54-
55-
//watch for pattern changes, and reload
56-
patternlab.events.on(events.PATTERNLAB_PATTERN_CHANGE, () => {
48+
//watch for builds to complete
49+
patternlab.events.on(events.PATTERNLAB_BUILD_END, () => {
5750
if (serverReady) {
5851
_module.reload({
5952
file: '',

0 commit comments

Comments
 (0)