-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolver.js
36 lines (32 loc) · 1.05 KB
/
resolver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import reactTreeWalker from 'react-tree-walker';
export default class Resolver {
constructor(app, adapter) {
this.app = app;
this.adapter = adapter;
}
resolve() {
let styles = [];
let components = [];
return reactTreeWalker(this.app, (element, instance) => {
if (instance && instance.getStyles) {
const stylesObject = instance.getStyles();
const alreadyContainStyle = styles.some(e =>
stylesObject.stylePaths.includes(e)
);
if (alreadyContainStyle) {
return;
}
styles = [...styles, ...stylesObject.stylePaths];
components = [...components, stylesObject.componentName];
}
}).then(() => {
return this.adapter.resolve(styles, components);
});
}
render() {
return this.resolve().then(rawResponse => {
return this.adapter.render(rawResponse);
});
}
}