Skip to content

Commit 414247b

Browse files
committed
Allow to merge two stylings
1 parent ff1d677 commit 414247b

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ Now you can write styles with the full power of JavaScript, `Button.styling.js`:
2020

2121
export let self = styling({
2222
backgroundColor: 'red',
23-
borderWidth: 1 + 10
23+
borderWidth: 1 + 10,
24+
25+
hover: {
26+
borderWidth: 100
27+
}
2428
})
2529

2630
And consume them, `Button.js`:

index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@
22
* @copyright 2015, Andrey Popp
33
*/
44

5+
var deepmerge = require('deepmerge');
6+
7+
var KEY = '@@styling';
8+
9+
function Styling(spec) {
10+
this[KEY] = spec;
11+
}
12+
13+
Styling.prototype.merge = function(other) {
14+
var nextSpec = deepmerge(this[KEY], other[KEY]);
15+
return new Styling(nextSpec);
16+
}
17+
518
function styling(spec) {
6-
return {'@@styling': spec};
19+
return new Styling(spec);
720
}
821

922
module.exports = styling;

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"main": "index.js",
66
"webpackLoader": "loader.js",
77
"author": "Andrey Popp <[email protected]>",
8-
"license": "MIT"
8+
"license": "MIT",
9+
"repository": "andreypopp/styling",
10+
"dependencies": {
11+
"deepmerge": "^0.2.10"
12+
}
913
}

0 commit comments

Comments
 (0)