* Replace a rule in the current stylesheet.
(nameOrSelector, decl, options)
| 91 | * Replace a rule in the current stylesheet. |
| 92 | */ |
| 93 | replaceRule(nameOrSelector, decl, options) { |
| 94 | const oldRule = this.rules.get(nameOrSelector) |
| 95 | if (!oldRule) return this.addRule(nameOrSelector, decl, options) |
| 96 | |
| 97 | const newRule = this.rules.replace(nameOrSelector, decl, options) |
| 98 | |
| 99 | if (newRule) { |
| 100 | this.options.jss.plugins.onProcessRule(newRule) |
| 101 | } |
| 102 | |
| 103 | if (this.attached) { |
| 104 | if (!this.deployed) return newRule |
| 105 | // Don't replace / delete rule directly if there is no stringified version yet. |
| 106 | // It will be inserted all together when .attach is called. |
| 107 | if (this.renderer) { |
| 108 | if (!newRule) { |
| 109 | this.renderer.deleteRule(oldRule) |
| 110 | } else if (oldRule.renderable) { |
| 111 | this.renderer.replaceRule(oldRule.renderable, newRule) |
| 112 | } |
| 113 | } |
| 114 | return newRule |
| 115 | } |
| 116 | |
| 117 | // We can't replace rules to a detached style node. |
| 118 | // We will redeploy the sheet once user will attach it. |
| 119 | this.deployed = false |
| 120 | |
| 121 | return newRule |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Insert rule into the StyleSheet |
nothing calls this directly
no test coverage detected