fixup! fix(tracker): typing, logs & remove duplicate sending

This commit is contained in:
Alex Kaminskii 2022-09-14 14:58:22 +02:00
parent 3ad978e263
commit b6ec7e5b48

View file

@ -17,20 +17,19 @@ export default function (app: App | null) {
return
}
const sendInserDeleteRule = app.safe(
(stylesheet: CSSStyleSheet, index: number, rule?: string) => {
const sheetID = styleSheetIDMap.get(stylesheet)
if (!sheetID) {
app.debug.warn('No sheedID found', stylesheet, styleSheetIDMap)
return
}
if (typeof rule === 'string') {
app.send(AdoptedSSInsertRuleURLBased(sheetID, rule, index, app.getBaseHref()))
} else {
app.send(AdoptedSSDeleteRule(sheetID, index))
}
},
)
const sendInserDeleteRule = app.safe((sheet: CSSStyleSheet, index: number, rule?: string) => {
const sheetID = styleSheetIDMap.get(sheet)
if (!sheetID) {
app.debug.log('StyleSheet not registered ', sheet, sheet.ownerNode)
// Sheet haven't been registered yet. Rules will be sent on registration.
return
}
if (typeof rule === 'string') {
app.send(AdoptedSSInsertRuleURLBased(sheetID, rule, index, app.getBaseHref()))
} else {
app.send(AdoptedSSDeleteRule(sheetID, index))
}
})
// TODO: proper rule insertion/removal (how?)
const sendReplaceGroupingRule = app.safe((rule: CSSGroupingRule) => {
@ -62,22 +61,22 @@ export default function (app: App | null) {
const { insertRule: groupInsertRule, deleteRule: groupDeleteRule } =
context.CSSGroupingRule.prototype
context.CSSStyleSheet.prototype.insertRule = function (rule: string, index = 0) {
context.CSSStyleSheet.prototype.insertRule = function (rule: string, index = 0): number {
sendInserDeleteRule(this, index, rule)
return insertRule.call(this, rule, index) as number
return insertRule.call(this, rule, index)
}
context.CSSStyleSheet.prototype.deleteRule = function (index: number) {
context.CSSStyleSheet.prototype.deleteRule = function (index: number): void {
sendInserDeleteRule(this, index)
return deleteRule.call(this, index) as number
return deleteRule.call(this, index)
}
context.CSSGroupingRule.prototype.insertRule = function (rule: string, index = 0) {
context.CSSGroupingRule.prototype.insertRule = function (rule: string, index = 0): number {
const result = groupInsertRule.call(this, rule, index) as number
sendReplaceGroupingRule(this)
return result
}
context.CSSGroupingRule.prototype.deleteRule = function (index = 0) {
const result = groupDeleteRule.call(this, index) as number
context.CSSGroupingRule.prototype.deleteRule = function (index = 0): void {
const result = groupDeleteRule.call(this, index) as void
sendReplaceGroupingRule(this)
return result
}
@ -102,6 +101,7 @@ export default function (app: App | null) {
const sheetID = nextID()
styleSheetIDMap.set(sheet, sheetID)
app.send(AdoptedSSAddOwner(sheetID, nodeID))
app.debug.log('StyleSheet registered ', sheet, node)
const rules = sheet.cssRules
for (let i = 0; i < rules.length; i++) {