Skip to content

Commit

Permalink
allow adding rules to a detached sheet #253
Browse files Browse the repository at this point in the history
  • Loading branch information
kof committed Jun 28, 2016
1 parent e7d34bb commit a66f295
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.0.2 / 2016-06-28

- allow adding rules to a detached sheet #253

## 4.0.1 / 2016-06-23

- fix jss.version in lib
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jss",
"description": "A lib for generating Style Sheets with JavaScript.",
"version": "4.0.1",
"version": "4.0.2",
"author": {
"name": "Oleg Slobodskoi",
"email": "oleg008@gmail.com"
Expand Down
19 changes: 14 additions & 5 deletions src/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,21 @@ export default class StyleSheet {
*/
addRule(name, style) {
const rule = this.createRule(name, style)
// Don't insert rule directly if there is no stringified version yet.
// It will be inserted all together when .attach is called.
if (this.deployed) {
const renderable = this.renderer.insertRule(rule)
if (this.options.link) rule.renderable = renderable

if (this.attached) {
// Don't insert rule directly if there is no stringified version yet.
// It will be inserted all together when .attach is called.
if (this.deployed) {
const renderable = this.renderer.insertRule(rule)
if (this.options.link) rule.renderable = renderable
}
// We can't add rules to a detached style node.
// We will redeploy the sheet once user will attach it.
}
else {
this.deployed = false
}

return rule
}

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('Functional: sheet', () => {
expect(sheet.getRule('a')).to.be(rule)
})

it('should register the rule after sheet.detach()', () => {
it('should add a rule to a detached sheet', () => {
sheet.detach()
const newRule = sheet.addRule('b', {float: 'right'})
sheet.attach()
Expand Down

0 comments on commit a66f295

Please sign in to comment.