Skip to content

Commit 2808483

Browse files
committed
improved runtime
1 parent c7233be commit 2808483

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

runtime/index.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
export function a(array) {
1+
export function create(items) {
2+
var array = [];
3+
items.forEach(function(elements) {
4+
elements.forEach(function(item) {
5+
array.push(item);
6+
});
7+
});
28
array.toString = function() {
3-
// T O D O
4-
return this;
9+
return this.map(function(item) {
10+
if(item[2]) {
11+
return '@media ' + item[2] + '{' + item[1] + '}';
12+
}
13+
return item[1]
14+
}).join('\n');
515
}
616
}
717

8-
export function b(id, source, sourceMap) {
9-
return [id, source, "", sourceMap];
18+
export function moduleWithSourceMap(id, source, sourceMap) {
19+
return [[id, source, '', sourceMap]];
1020
}
1121

12-
export function c(id, source) {
13-
return b(id, source, null);
22+
export function moduleWithoutSourceMap(id, source) {
23+
return moduleWithSourceMap(id, source, null);
1424
}
1525

16-
export function d(data, mediaQuery) {
26+
export function importStylesheet(data, mediaQuery) {
27+
if(typeof data === 'string')
28+
return moduleWithoutSourceMap(null, data);
1729
return data.map(function(item) {
1830
return [item[0], item[1], joinMediaQuery(item[2], mediaQuery), item[3]];
1931
})
2032
}
2133

2234
function joinMediaQuery(itemA, itemB) {
23-
if(itemA && itemB) return "(" + itemA + ") and (" + itemB + ")";
24-
return itemA || itemB || "";
35+
if(itemA && itemB) return '(' + itemA + ') and (' + itemB + ')';
36+
return itemA || itemB || '';
2537
}

src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ export default function loader(source, map) {
9999
declarations.join('\n'),
100100
'',
101101
'// CSS',
102-
'export default runtime.a([',
102+
'export default runtime.create([',
103103
].concat(
104104
includedStylesheetsArray.map((include) => {
105105
if(!include.mediaQuery) return ` ${include.name},`;
106-
return ` runtime.d(${include.name}, ${JSON.stringify(include.mediaQuery)},`;
106+
return ` runtime.importStylesheet(${include.name}, ${JSON.stringify(include.mediaQuery)},`;
107107
})
108108
).concat([
109109
sourceMap ?
110-
` runtime.b(module.id, ${cssJs}, ${sourceMap})` :
111-
` runtime.c(module.id, ${cssJs})`,
110+
` runtime.moduleWithSourceMap(module.id, ${cssJs}, ${sourceMap})` :
111+
` runtime.moduleWithoutSourceMap(module.id, ${cssJs})`,
112112
']);'
113113
]).join('\n');
114114
}

0 commit comments

Comments
 (0)