Skip to content

Commit 4b30a35

Browse files
committed
Adjust: The execution time of the callback to get the result is moved to before the result is returned
1 parent ba7e14b commit 4b30a35

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

src/api.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,17 @@ export function createCrawlPage(xCrawlConfig: LoaderXCrawlConfig) {
405405

406406
function crawlPage(
407407
config: (string | CrawlPageDetailConfig)[],
408-
callback?: (res: CrawlPageSingleRes) => void
408+
callback?: (res: CrawlPageSingleRes[]) => void
409409
): Promise<CrawlPageSingleRes[]>
410410

411411
function crawlPage(
412412
config: CrawlPageAdvancedConfig,
413-
callback?: (res: CrawlPageSingleRes) => void
413+
callback?: (res: CrawlPageSingleRes[]) => void
414414
): Promise<CrawlPageSingleRes[]>
415415

416416
async function crawlPage(
417417
config: UniteCrawlPageConfig,
418-
callback?: (res: CrawlPageSingleRes) => void
418+
callback?: (res: any) => void
419419
): Promise<CrawlPageSingleRes | CrawlPageSingleRes[]> {
420420
const cId = ++cIdCount
421421

@@ -484,10 +484,6 @@ export function createCrawlPage(xCrawlConfig: LoaderXCrawlConfig) {
484484
data
485485
}
486486

487-
if (callback) {
488-
callback(crawlRes)
489-
}
490-
491487
return crawlRes
492488
})
493489

@@ -500,6 +496,10 @@ export function createCrawlPage(xCrawlConfig: LoaderXCrawlConfig) {
500496
? crawlResArr
501497
: crawlResArr[0]
502498

499+
if (callback) {
500+
callback(crawlRes)
501+
}
502+
503503
return crawlRes
504504
}
505505

@@ -576,17 +576,17 @@ export function createCrawlData(xCrawlConfig: LoaderXCrawlConfig) {
576576

577577
function crawlData<T = any>(
578578
config: (string | CrawlDataDetailConfig)[],
579-
callback?: (res: CrawlDataSingleRes<T>) => void
579+
callback?: (res: CrawlDataSingleRes<T>[]) => void
580580
): Promise<CrawlDataSingleRes<T>[]>
581581

582582
function crawlData<T = any>(
583583
config: CrawlDataAdvancedConfig,
584-
callback?: (res: CrawlDataSingleRes<T>) => void
584+
callback?: (res: CrawlDataSingleRes<T>[]) => void
585585
): Promise<CrawlDataSingleRes<T>[]>
586586

587587
async function crawlData<T = any>(
588588
config: UniteCrawlDataConfig,
589-
callback?: (res: CrawlDataSingleRes<T>) => void
589+
callback?: (res: any) => void
590590
): Promise<CrawlDataSingleRes<T> | CrawlDataSingleRes<T>[]> {
591591
const { crawlDetails, intervalTime } = createCrawlDataConfig(
592592
xCrawlConfig,
@@ -632,10 +632,6 @@ export function createCrawlData(xCrawlConfig: LoaderXCrawlConfig) {
632632
crawlRes.data = { ...crawlSingleRes, data }
633633
}
634634

635-
if (callback) {
636-
callback(crawlRes)
637-
}
638-
639635
return crawlRes
640636
})
641637

@@ -645,6 +641,10 @@ export function createCrawlData(xCrawlConfig: LoaderXCrawlConfig) {
645641
? crawlResArr
646642
: crawlResArr[0]
647643

644+
if (callback) {
645+
callback(crawlRes)
646+
}
647+
648648
return crawlRes
649649
}
650650

@@ -659,17 +659,17 @@ export function createCrawlFile(xCrawlConfig: LoaderXCrawlConfig) {
659659

660660
function crawlFile(
661661
config: CrawlFileDetailConfig[],
662-
callback?: (res: CrawlFileSingleRes) => void
662+
callback?: (res: CrawlFileSingleRes[]) => void
663663
): Promise<CrawlFileSingleRes[]>
664664

665665
function crawlFile(
666666
config: CrawlFileAdvancedConfig,
667-
callback?: (res: CrawlFileSingleRes) => void
667+
callback?: (res: CrawlFileSingleRes[]) => void
668668
): Promise<CrawlFileSingleRes[]>
669669

670670
async function crawlFile(
671671
config: UniteCrawlFileConfig,
672-
callback?: (res: CrawlFileSingleRes) => void
672+
callback?: (res: any) => void
673673
): Promise<CrawlFileSingleRes | CrawlFileSingleRes[]> {
674674
const { crawlDetails, intervalTime, onBeforeSaveFile } =
675675
createCrawlFileConfig(xCrawlConfig, config)
@@ -762,17 +762,9 @@ export function createCrawlFile(xCrawlConfig: LoaderXCrawlConfig) {
762762
filePath
763763
}
764764
}
765-
766-
if (callback) {
767-
callback(crawlRes)
768-
}
769765
})
770766

771767
saveFileQueue.push(saveFileItem)
772-
} else {
773-
if (callback) {
774-
callback(crawlRes)
775-
}
776768
}
777769

778770
return crawlRes
@@ -816,6 +808,10 @@ export function createCrawlFile(xCrawlConfig: LoaderXCrawlConfig) {
816808
? crawlResArr
817809
: crawlResArr[0]
818810

811+
if (callback) {
812+
callback(crawlRes)
813+
}
814+
819815
return crawlRes
820816
}
821817

src/types/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ export interface XCrawlInstance {
4343

4444
(
4545
config: (string | CrawlPageDetailConfig)[],
46-
callback?: (res: CrawlPageSingleRes) => void
46+
callback?: (res: CrawlPageSingleRes[]) => void
4747
): Promise<CrawlPageSingleRes[]>
4848

4949
(
5050
config: CrawlPageAdvancedConfig,
51-
callback?: (res: CrawlPageSingleRes) => void
51+
callback?: (res: CrawlPageSingleRes[]) => void
5252
): Promise<CrawlPageSingleRes[]>
5353
}
5454

@@ -65,12 +65,12 @@ export interface XCrawlInstance {
6565

6666
<T = any>(
6767
config: (string | CrawlDataDetailConfig)[],
68-
callback?: (res: CrawlDataSingleRes<T>) => void
68+
callback?: (res: CrawlDataSingleRes<T>[]) => void
6969
): Promise<CrawlDataSingleRes<T>[]>
7070

7171
<T = any>(
7272
config: CrawlDataAdvancedConfig,
73-
callback?: (res: CrawlDataSingleRes<T>) => void
73+
callback?: (res: CrawlDataSingleRes<T>[]) => void
7474
): Promise<CrawlDataSingleRes<T>[]>
7575
}
7676

@@ -82,12 +82,12 @@ export interface XCrawlInstance {
8282

8383
(
8484
config: CrawlFileDetailConfig[],
85-
callback?: (res: CrawlFileSingleRes) => void
85+
callback?: (res: CrawlFileSingleRes[]) => void
8686
): Promise<CrawlFileSingleRes[]>
8787

8888
(
8989
config: CrawlFileAdvancedConfig,
90-
callback?: (res: CrawlFileSingleRes) => void
90+
callback?: (res: CrawlFileSingleRes[]) => void
9191
): Promise<CrawlFileSingleRes[]>
9292
}
9393

0 commit comments

Comments
 (0)