(index, rule)
| 144 | } |
| 145 | |
| 146 | replaceRule(index, rule) { |
| 147 | if (this._optimizeForSpeed || typeof window === 'undefined') { |
| 148 | const sheet = |
| 149 | typeof window !== 'undefined' ? this.getSheet() : this._serverSheet |
| 150 | if (!rule.trim()) { |
| 151 | rule = this._deletedRulePlaceholder |
| 152 | } |
| 153 | |
| 154 | if (!sheet.cssRules[index]) { |
| 155 | // @TBD Should we throw an error? |
| 156 | return index |
| 157 | } |
| 158 | |
| 159 | sheet.deleteRule(index) |
| 160 | |
| 161 | try { |
| 162 | sheet.insertRule(rule, index) |
| 163 | } catch (error) { |
| 164 | if (!isProd) { |
| 165 | console.warn( |
| 166 | `StyleSheet: illegal rule: \n\n${rule}\n\nSee https://stackoverflow.com/q/20007992 for more info` |
| 167 | ) |
| 168 | } |
| 169 | |
| 170 | // In order to preserve the indices we insert a deleteRulePlaceholder |
| 171 | sheet.insertRule(this._deletedRulePlaceholder, index) |
| 172 | } |
| 173 | } else { |
| 174 | const tag = this._tags[index] |
| 175 | invariant(tag, `old rule at index \`${index}\` not found`) |
| 176 | tag.textContent = rule |
| 177 | } |
| 178 | |
| 179 | return index |
| 180 | } |
| 181 | |
| 182 | deleteRule(index) { |
| 183 | if (typeof window === 'undefined') { |
no test coverage detected