๐ผ Previously @github, @basecamp, @rails.
I'm not available for hire on sites like Upwork.
License: MIT License
How about making available at https://www.npmjs.com/package/selector-set ?
Just stumbled upon this bug in selector-observer with jsdom (related bug).
The selector-observer case:
const { JSDOM } = require("jsdom")
const {window} = new JSDOM(``, {});
const {document} = window
import {observe} from 'selector-observer'
let o1 = observe('.foo', {})
o1.abort()
let o2 = observe('.foo', {})
o2.abort()
let o3 = observe('.bar', {})
o3.abort()
await Promise.resolve().then()
document.body.appendChild(document.createElement('div'))
This gives error in jsdom env:
Error: Uncaught [TypeError: Cannot read property '0' of undefined]
at reportException (C:\projects\spect\node_modules\window\node_modules\jsdom\lib\jsdom\living\helpers\runtime-script-errors.js:62:24)
at notifyMutationObservers (C:\projects\spect\node_modules\window\node_modules\jsdom\lib\jsdom\living\helpers\mutation-observers.js:166:11)
at C:\projects\spect\node_modules\window\node_modules\jsdom\lib\jsdom\living\helpers\mutation-observers.js:133:5
at processTicksAndRejections (internal/process/task_queues.js:82:5)
at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:59:3)
at C:\projects\spect\node_modules\esm\esm.js:1:34535
at C:\projects\spect\node_modules\esm\esm.js:1:34176
at process.<anonymous> (C:\projects\spect\node_modules\esm\esm.js:1:34506)
at Function.<anonymous> (C:\projects\spect\node_modules\esm\esm.js:1:296856)
at Function.<anonymous> (C:\projects\spect\node_modules\esm\esm.js:1:296555) TypeError: Cannot read property '0' of undefined
at results_from (C:\projects\spect\node_modules\nwsapi\src\nwsapi.js:1522:48)
at Object._querySelectorAll [as select] (C:\projects\spect\node_modules\nwsapi\src\nwsapi.js:1499:15)
at HTMLDivElementImpl.querySelectorAll (C:\projects\spect\node_modules\window\node_modules\jsdom\lib\jsdom\living\nodes\ParentNode-impl.js:72:26)
at HTMLDivElement.querySelectorAll (C:\projects\spect\node_modules\window\node_modules\jsdom\lib\jsdom\living\generated\Element.js:839:47)
at SelectorSet._2e9โ.r.SelectorSet.querySelectorAll (C:\projects\spect\node_modules\selector-set\selector-set.next.js:53:18)
at SelectorSet._2e9โ.r.SelectorSet.queryAll (C:\projects\spect\node_modules\selector-set\selector-set.next.js:346:18)
at addNodes (C:\projects\spect\node_modules\selector-observer\dist\index.esm.js:343:51)
at handleMutations$1 (C:\projects\spect\node_modules\selector-observer\dist\index.esm.js:310:7)
at SelectorObserver.handleRootMutations (C:\projects\spect\node_modules\selector-observer\dist\index.esm.js:599:3)
at notifyMutationObservers (C:\projects\spect\node_modules\window\node_modules\jsdom\lib\jsdom\living\helpers\mutation-observers.js:158:14)
Delving in debugging, selector-observer
forms wrong selector even if it was aborted.
Turns out, selector-set
, after calling remove
, still keeps set.selectors
:
var set = new SelectorSet();
set.add('.foo')
set.add('.foo')
console.log(set.selectors) // ['.foo', '.foo']
set.remove('.foo')
console.log(set.selectors) // ['.foo', '.foo']
@josh is that by design?
How i can use with typescript?
No typings in repo, no in @types
.
My tsconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"baseUrl": "./",
"paths": { "*": ["typings/*"] }
}
My typings/selector-set/index.d.ts
:
declare class SelectorSet<T> {
size: number;
matchesSelector: (el: Element, selector: string) => boolean;
querySelectorAll: (selectors: string, context: Element) => Array<Element>;
indexes: Array<{name: string, selector: (selector: string) => string, element: (el: Element) => Array<string>}>;
add(selector: string, data: T): void;
remove(selector: string, data?: T): void;
matches(el: Element): Array<{selector: string, data: T}>;
queryAll(context: Element): Array<{selector: string, data: T, elements: Array<Element>}>;
logDefaultIndexUsed: ({ selector, data }: { selector: string, data: T }) => void;
}
export default SelectorSet;
Usage:
import SelectorSet from 'selector-set';
const selectorSet = new SelectorSet();
Affects TypeError: selector_set_1.default is not a constructor
Will show up in bower searches
queryAll
can do better than https://github.com/josh/selector-set/blob/master/selector-set.next.js#L377:
instead of selecting all elements matching all rules in context, individual selectors may have up to 25 times better performance via getElementsBy*
, which is O(c) - compared to best-case querySelectorAll
O(n).
For some cases that can reduce queryAll
complexity from O(rules * nodes) to O(rules * c).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.