Skip to content

Commit 4703bc5

Browse files
committed
txt(val: string:cb) callback signature 4th parameter
1 parent 5417d0f commit 4703bc5

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/CssChain.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface CssChainCollection<T> extends Array<AnyElement&T>, AnyElement
6161
/** sets text for each element from `val` */
6262
txt(val: string, css: string|CssChainCollection<T>): CssChainCollection<T>;
6363
/** sets text for each element from callback */
64-
txt( valCb: (el:T,i:number,arr:CssChainCollection<T>)=>string, css: string|CssChainCollection<T>): CssChainCollection<T>;
64+
txt( valCb: (el:T,i:number,arrCss:CssChainCollection<T>,arrThis:CssChainCollection<T>)=>string, css: string|CssChainCollection<T>): CssChainCollection<T>;
6565
/** sets text for children elements defined by css, returns original collection */
6666
txt(val: any, css: string|CssChainCollection<T>): CssChainCollection<T>;
6767

src/CssChain.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ CssChainT extends Array
206206
get innerText(){ return this.txt() }
207207
set innerText( val ){ return this.txt( val ) }
208208
txt( val, css=undefined )
209-
{ const arr = css? this.$(css): this;
209+
{ const $ = this.$(css);
210210
if( val === undefined )
211-
return collectionText( arr );
212-
arr.forEach( isFn(val)
213-
? (n,i)=>setNodeText(n,val(n,i,arr))
211+
return collectionText( $ );
212+
$.forEach( isFn(val)
213+
? (n,i)=>setNodeText(n,val(n,i,$,this))
214214
: n=>setNodeText(n,val) );
215215
return this
216216
}

test/CssChain-types.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('CssChain', () => {
6565
expect($X.value).to.equal(undefined); // INPUT prop
6666
};
6767
it('$() matched document', async () => {
68-
const el = await fixture(html`
68+
await fixture(html`
6969
<main>Hi</main>`);
7070
const $X = $$();
7171
expect($X[0]).to.equal(document);
@@ -371,6 +371,12 @@ describe('CssChain', () => {
371371
expect($e.txt()).to.equal('b1-0-2:b2-1-2');
372372
expect($e.$('button').length).to.equal(2);
373373
expect($e.$('button').txt()).to.equal('b1-0-2b2-1-2');
374+
375+
const cb4 = (e:HTMLElementMixin,i:number,arrCss: HTMLElementMixin[],arrThis: HTMLElementMixin[])=>`${e.id}-${i}-${arrCss.length}-${arrThis.length}`;
376+
expect($e.txt(cb4,'button').length).to.equal(1);
377+
expect($e.txt()).to.equal('b1-0-2-1:b2-1-2-1');
378+
expect($e.$('button').length).to.equal(2);
379+
expect($e.$('button').txt()).to.equal('b1-0-2-1b2-1-2-1');
374380
});
375381

376382
});

0 commit comments

Comments
 (0)