Skip to content

Commit 42d7634

Browse files
Saviiochuan6
authored andcommitted
feat: ignore unneccssary output
1 parent 45de6bf commit 42d7634

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/storage/modules/QueryToken.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { Observable, OperatorFunction, from } from 'rxjs'
2-
import { combineAll, map, publishReplay, refCount, skipWhile, switchMap, take, tap } from 'rxjs/operators'
2+
import { combineAll, filter, map, publishReplay, refCount, skipWhile, switchMap, take, tap } from 'rxjs/operators'
33
import { Selector } from './Selector'
44
import { ProxySelector } from './ProxySelector'
55
import { assert } from '../../utils/assert'
66
import { TokenConsumed } from '../../exception/token'
7-
import { diff, Ops } from '../../utils/diff'
7+
import { diff, Ops, OpsType } from '../../utils/diff'
88

9-
export interface TraceResult<T> {
9+
export type TraceResult<T> = Ops & {
1010
result: T[]
11-
ops: Ops
1211
}
1312

1413
export type SelectorMeta<T> = Selector<T> | ProxySelector<T>
@@ -61,8 +60,9 @@ export class QueryToken<T> {
6160
return this.changes().pipe(
6261
map((result: T[]) => {
6362
const ops = diff(this.lastEmit, result, pk)
64-
return { result, ops }
63+
return { result, ...ops }
6564
}),
65+
filter((xs) => xs.type !== OpsType.ShouldSkip),
6666
tap(({ result }) => (this.lastEmit = result)),
6767
)
6868
}

src/utils/diff.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export enum OpsType {
1616
// 2 = success but should skip
1717
Error,
1818
Success,
19-
SuccessAndSkip,
19+
ShouldSkip,
2020
}
2121

2222
export type Ops = {
@@ -46,7 +46,7 @@ export const getPatchResult = <T>(oldList: T[], newList: T[], ops: Ops): T[] =>
4646
switch (ops.type) {
4747
case OpsType.Error:
4848
return newList
49-
case OpsType.SuccessAndSkip:
49+
case OpsType.ShouldSkip:
5050
return oldList
5151
case OpsType.Success:
5252
default:
@@ -176,7 +176,7 @@ export function diff<T>(oldList: T[], newList: T[], pk = '_id'): Ops {
176176

177177
const arrayIsSame = reused === curr.length && prev.length === curr.length && reused !== 0
178178
return {
179-
type: arrayIsSame ? OpsType.SuccessAndSkip : OpsType.Success,
179+
type: arrayIsSame ? OpsType.ShouldSkip : OpsType.Success,
180180
ops: ret,
181181
}
182182
}

test/specs/storage/modules/QueryToken.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export default describe('QueryToken Testcase', () => {
9595
.traces('_id')
9696
.pipe(skip(1))
9797
.subscribe((r) => {
98-
const { result, ops } = r
98+
const { result, type, ops } = r
9999
expect(result[0].note).to.equal(newNote)
100-
expect(ops.type).to.equal(1)
101-
ops.ops.forEach((op: Op, index: number) => {
100+
expect(type).to.equal(1)
101+
ops.forEach((op: Op, index: number) => {
102102
if (index === 0) {
103103
expect(op.type).to.equal(1)
104104
} else {
@@ -123,10 +123,10 @@ export default describe('QueryToken Testcase', () => {
123123
.traces('_id')
124124
.pipe(skip(1))
125125
.subscribe((r) => {
126-
const { result, ops } = r
126+
const { result, type, ops } = r
127127
expect(result[0].note).to.equal(newNote)
128-
expect(ops.type).to.equal(1)
129-
ops.ops.forEach((op: Op, index: number) => {
128+
expect(type).to.equal(1)
129+
ops.forEach((op: Op, index: number) => {
130130
if (index === 0) {
131131
expect(op.type).to.equal(1)
132132
} else {
@@ -241,8 +241,8 @@ export default describe('QueryToken Testcase', () => {
241241

242242
const combined = queryToken.combine(queryToken2)
243243
combined.traces().subscribe((r) => {
244-
expect(r.ops.type).to.equal(1)
245-
r.ops.ops.forEach((op: Op, index: number) => {
244+
expect(r.type).to.equal(1)
245+
r.ops.forEach((op: Op, index: number) => {
246246
if (index < 25) {
247247
expect(op.type).to.equal(0)
248248
} else {
@@ -270,8 +270,8 @@ export default describe('QueryToken Testcase', () => {
270270

271271
const combined = queryToken.combine(queryToken2)
272272
combined.traces().subscribe((r) => {
273-
expect(r.ops.type).to.equal(1)
274-
r.ops.ops.forEach((op: Op, index: number) => {
273+
expect(r.type).to.equal(1)
274+
r.ops.forEach((op: Op, index: number) => {
275275
if (index < 25) {
276276
expect(op.type).to.equal(0)
277277
} else {
@@ -374,8 +374,8 @@ export default describe('QueryToken Testcase', () => {
374374
queryToken.traces().subscribe()
375375
const concated = queryToken.concat(queryToken2)
376376
concated.traces().subscribe((r) => {
377-
expect(r.ops.type).to.equal(1)
378-
r.ops.ops.forEach((op: Op, index: number) => {
377+
expect(r.type).to.equal(1)
378+
r.ops.forEach((op: Op, index: number) => {
379379
if (index < 25) {
380380
expect(op.type).to.equal(0)
381381
} else {

tools/publish.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ Promise.all([
4646
write('dist/cjs/README.md', README),
4747
])
4848
.then(() => {
49-
const { stderr, stdout } = shelljs.exec('npm publish dist/cjs')
49+
const { stderr, stdout } = shelljs.exec('npm publish dist/cjs --tag=next')
5050
if (stderr) {
5151
throw stderr
5252
}
5353
console.info(stdout)
5454
})
5555
.then(() => {
56-
const { stderr, stdout } = shelljs.exec('npm publish dist/es')
56+
const { stderr, stdout } = shelljs.exec('npm publish dist/es --tag=next')
5757
if (stderr) {
5858
throw stderr
5959
}

0 commit comments

Comments
 (0)