Skip to content

Instantly share code, notes, and snippets.

@TimvdLippe
Created July 28, 2017 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save TimvdLippe/8a1a74f4d80dbe6eb67558b328623c0f to your computer and use it in GitHub Desktop.
Save TimvdLippe/8a1a74f4d80dbe6eb67558b328623c0f to your computer and use it in GitHub Desktop.
Script to obtain stats from Polymer metadata
window.counts = {}
for (const condition of [
'computed trigger.rootProperty equals name',
'computed trigger.rootProperty is name until first dot',
'computed arg.value is empty',
'computed arg.literal is false',
'computed arg.structured is false',
'computed info.methodInfo equals compute effect name',
'computed trigger.wildcard is false',
'computed trigger.literal is false',
'computed arg.name equals effect name',
'reflect info.attrName equals name',
'reflect info.attrName is dashCase of name',
'notify info.property equals name',
'notify info.eventName equals name-changed',
'notify info.eventName is dashCase of name-changed',
'readOnly effect is undefined',
'observe info.property equals name',
'observe trigger.value is empty',
'observe trigger.literal is false',
'observe trigger.structured is false',
'observe trigger.literal is undefined',
'observe trigger.literal is falsy',
'observe trigger.value is undefined',
'observe trigger.value is falsy',
'observe trigger.name equals name',
'observe info.dynamicFn is false',
'observe info.dynamicFn is undefined',
'observe info.dynamicFn is falsy'
]) {
window.counts[condition] = {
[true]: 0, [false]: 0
}
}
for (const registration of Polymer.telemetry.registrations) {
const element = registration.constructor.prototype;
if (element.__computeEffects) {
for (const [name, effects] of Object.entries(element.__computeEffects)) {
for (const effect of effects) {
window.counts['computed trigger.rootProperty equals name'][effect.trigger.rootProperty === effect.trigger.name]++
window.counts['computed trigger.wildcard is false'][effect.trigger.wildcard === false]++
window.counts['computed trigger.literal is false'][effect.trigger.literal === false]++
window.counts['computed trigger.rootProperty is name until first dot'][effect.trigger.name.split('.')[0] === effect.trigger.rootProperty]++
window.counts['computed info.methodInfo equals compute effect name'][effect.info.methodInfo === name]++
for (const arg of effect.info.args) {
window.counts['computed arg.value is empty'][arg.value === '']++;
window.counts['computed arg.literal is false'][arg.literal === false]++
window.counts['computed arg.structured is false'][arg.structured === false]++
window.counts['computed arg.name equals effect name'][arg.name === name]++
}
}
}
}
if (element.__reflectEffects) {
for (const [name, effects] of Object.entries(element.__reflectEffects)) {
for (const effect of effects) {
window.counts['reflect info.attrName equals name'][effect.info.attrName === name]++
window.counts['reflect info.attrName is dashCase of name'][Polymer.CaseMap.camelToDashCase(name) === effect.info.attrName]++
}
}
}
if (element.__notifyEffects) {
for (const [name, effects] of Object.entries(element.__notifyEffects)) {
for (const effect of effects) {
window.counts['notify info.property equals name'][effect.info.property === name]++
window.counts['notify info.eventName equals name-changed'][effect.info.eventName === `${name}-changed`]++
window.counts['notify info.eventName is dashCase of name-changed'][effect.info.eventName === `${Polymer.CaseMap.camelToDashCase(name)}-changed`]++
}
}
}
if (element.__readOnly) {
for (const [name, effects] of Object.entries(element.__readOnly)) {
for (const effect of effects) {
window.counts['readOnly effect is undefined'][effect === undefined]++
}
}
}
if (element.__observeEffects) {
for (const [name, effects] of Object.entries(element.__observeEffects)) {
for (const effect of effects) {
window.counts['observe info.property equals name'][effect.info.property === name]++
window.counts['observe info.dynamicFn is false'][effect.info.dynamicFn === false]++
window.counts['observe info.dynamicFn is undefined'][effect.info.dynamicFn === undefined]++
window.counts['observe info.dynamicFn is falsy'][!effect.info.dynamicFn]++
window.counts['observe trigger.value is empty'][effect.trigger.value === '']++;
window.counts['observe trigger.value is undefined'][effect.trigger.value === undefined]++;
window.counts['observe trigger.value is falsy'][!effect.trigger.value]++;
window.counts['observe trigger.literal is false'][effect.trigger.literal === false]++
window.counts['observe trigger.literal is undefined'][effect.trigger.literal === undefined]++
window.counts['observe trigger.literal is falsy'][!effect.trigger.literal]++
window.counts['observe trigger.structured is false'][effect.trigger.structured === false]++
window.counts['observe trigger.name equals name'][effect.trigger.name === name]++
}
}
}
}
console.table(window.counts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment