MCPcopy
hub / github.com/cssinjs/jss / replaceRule

Method replaceRule

packages/jss/src/StyleSheet.js:93–122  ·  view source on GitHub ↗

* Replace a rule in the current stylesheet.

(nameOrSelector, decl, options)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

addRuleMethod · 0.95
replaceMethod · 0.80
getMethod · 0.65
onProcessRuleMethod · 0.65
deleteRuleMethod · 0.65
replaceRuleMethod · 0.65

Tested by

no test coverage detected