@wixc3/patterns
Advanced tools
Comparing version 9.0.0 to 9.1.0
@@ -12,2 +12,6 @@ /** | ||
remove(name: string): void; | ||
list(): { | ||
name: string; | ||
timeout: number; | ||
}[]; | ||
} | ||
@@ -14,0 +18,0 @@ export type DisposeFunction = () => unknown; |
@@ -42,2 +42,5 @@ "use strict"; | ||
} | ||
list() { | ||
return Array.from(this.disposables.values()).map((d) => ({ name: d.name, timeout: d.timeout })); | ||
} | ||
} | ||
@@ -44,0 +47,0 @@ exports.Disposables = Disposables; |
@@ -61,3 +61,3 @@ import { GroupConstraints } from './constraints'; | ||
*/ | ||
registerGroup: (name: string, constraints: GroupConstraints[] | GroupConstraints) => void; | ||
registerGroup: (name: string, _constraints: GroupConstraints[] | GroupConstraints) => void; | ||
add: (disposable: Disposable, options?: DisposableOptions) => void; | ||
@@ -69,3 +69,15 @@ /** | ||
dispose: () => Promise<void>; | ||
list: () => { | ||
constrains: GroupConstraints[]; | ||
groups: { | ||
name: string; | ||
disposables: { | ||
name: string; | ||
timeout: number; | ||
}[]; | ||
totalTimeout: number; | ||
}[]; | ||
totalTimeout: number; | ||
}; | ||
}; | ||
//# sourceMappingURL=disposal-groups.d.ts.map |
@@ -57,2 +57,3 @@ "use strict"; | ||
const groups = [createGroup(exports.DEFAULT_GROUP)]; | ||
const constrains = []; | ||
return { | ||
@@ -63,5 +64,6 @@ /** | ||
*/ | ||
registerGroup: (name, constraints) => { | ||
const _constraints = (0, constraints_1.normalizeConstraints)(constraints, name, groups); | ||
const { lastAfter, firstBefore } = (0, constraints_1.getValidatedConstantsGroups)(_constraints, groups); | ||
registerGroup: (name, _constraints) => { | ||
const nConstraints = (0, constraints_1.normalizeConstraints)(_constraints, name, groups); | ||
const { lastAfter, firstBefore } = (0, constraints_1.getValidatedConstantsGroups)(nConstraints, groups); | ||
constrains.push(...nConstraints); | ||
if (lastAfter > 0) { | ||
@@ -93,2 +95,18 @@ groups.splice(lastAfter + 1, 0, createGroup(name)); | ||
}, | ||
list: () => { | ||
const g = groups.map((g) => { | ||
const { name } = g; | ||
const disposables = g.disposables.list(); | ||
return { | ||
name, | ||
disposables, | ||
totalTimeout: disposables.reduce((acc, d) => acc + d.timeout, 0), | ||
}; | ||
}); | ||
return { | ||
constrains, | ||
groups: g, | ||
totalTimeout: g.reduce((acc, g) => acc + g.totalTimeout, 0), | ||
}; | ||
}, | ||
}; | ||
@@ -95,0 +113,0 @@ } |
@@ -12,2 +12,6 @@ /** | ||
remove(name: string): void; | ||
list(): { | ||
name: string; | ||
timeout: number; | ||
}[]; | ||
} | ||
@@ -14,0 +18,0 @@ export type DisposeFunction = () => unknown; |
@@ -38,2 +38,5 @@ import { find } from '@wixc3/common'; | ||
} | ||
list() { | ||
return Array.from(this.disposables.values()).map((d) => ({ name: d.name, timeout: d.timeout })); | ||
} | ||
} | ||
@@ -40,0 +43,0 @@ async function disposeOf({ dispose }) { |
@@ -61,3 +61,3 @@ import { GroupConstraints } from './constraints'; | ||
*/ | ||
registerGroup: (name: string, constraints: GroupConstraints[] | GroupConstraints) => void; | ||
registerGroup: (name: string, _constraints: GroupConstraints[] | GroupConstraints) => void; | ||
add: (disposable: Disposable, options?: DisposableOptions) => void; | ||
@@ -69,3 +69,15 @@ /** | ||
dispose: () => Promise<void>; | ||
list: () => { | ||
constrains: GroupConstraints[]; | ||
groups: { | ||
name: string; | ||
disposables: { | ||
name: string; | ||
timeout: number; | ||
}[]; | ||
totalTimeout: number; | ||
}[]; | ||
totalTimeout: number; | ||
}; | ||
}; | ||
//# sourceMappingURL=disposal-groups.d.ts.map |
@@ -54,2 +54,3 @@ import { getValidatedConstantsGroups, normalizeConstraints } from './constraints'; | ||
const groups = [createGroup(DEFAULT_GROUP)]; | ||
const constrains = []; | ||
return { | ||
@@ -60,5 +61,6 @@ /** | ||
*/ | ||
registerGroup: (name, constraints) => { | ||
const _constraints = normalizeConstraints(constraints, name, groups); | ||
const { lastAfter, firstBefore } = getValidatedConstantsGroups(_constraints, groups); | ||
registerGroup: (name, _constraints) => { | ||
const nConstraints = normalizeConstraints(_constraints, name, groups); | ||
const { lastAfter, firstBefore } = getValidatedConstantsGroups(nConstraints, groups); | ||
constrains.push(...nConstraints); | ||
if (lastAfter > 0) { | ||
@@ -90,4 +92,20 @@ groups.splice(lastAfter + 1, 0, createGroup(name)); | ||
}, | ||
list: () => { | ||
const g = groups.map((g) => { | ||
const { name } = g; | ||
const disposables = g.disposables.list(); | ||
return { | ||
name, | ||
disposables, | ||
totalTimeout: disposables.reduce((acc, d) => acc + d.timeout, 0), | ||
}; | ||
}); | ||
return { | ||
constrains, | ||
groups: g, | ||
totalTimeout: g.reduce((acc, g) => acc + g.totalTimeout, 0), | ||
}; | ||
}, | ||
}; | ||
} | ||
//# sourceMappingURL=disposal-groups.js.map |
{ | ||
"name": "@wixc3/patterns", | ||
"version": "9.0.0", | ||
"version": "9.1.0", | ||
"description": "A utility for saving objects to be disposed", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
@@ -46,2 +46,6 @@ import { find } from '@wixc3/common'; | ||
} | ||
list() { | ||
return Array.from(this.disposables.values()).map((d) => ({ name: d.name, timeout: d.timeout })); | ||
} | ||
} | ||
@@ -48,0 +52,0 @@ |
@@ -75,2 +75,3 @@ import { DisposalGroup, getValidatedConstantsGroups, GroupConstraints, normalizeConstraints } from './constraints'; | ||
const groups: DisposalGroup[] = [createGroup(DEFAULT_GROUP)]; | ||
const constrains: GroupConstraints[] = []; | ||
return { | ||
@@ -81,5 +82,6 @@ /** | ||
*/ | ||
registerGroup: (name: string, constraints: GroupConstraints[] | GroupConstraints) => { | ||
const _constraints: GroupConstraints[] = normalizeConstraints(constraints, name, groups); | ||
const { lastAfter, firstBefore } = getValidatedConstantsGroups(_constraints, groups); | ||
registerGroup: (name: string, _constraints: GroupConstraints[] | GroupConstraints) => { | ||
const nConstraints: GroupConstraints[] = normalizeConstraints(_constraints, name, groups); | ||
const { lastAfter, firstBefore } = getValidatedConstantsGroups(nConstraints, groups); | ||
constrains.push(...nConstraints); | ||
@@ -114,3 +116,20 @@ if (lastAfter > 0) { | ||
}, | ||
list: () => { | ||
const g = groups.map((g) => { | ||
const { name } = g; | ||
const disposables = g.disposables.list(); | ||
return { | ||
name, | ||
disposables, | ||
totalTimeout: disposables.reduce((acc, d) => acc + d.timeout, 0), | ||
}; | ||
}); | ||
return { | ||
constrains, | ||
groups: g, | ||
totalTimeout: g.reduce((acc, g) => acc + g.totalTimeout, 0), | ||
}; | ||
}, | ||
}; | ||
} |
@@ -74,3 +74,31 @@ import { expect, use } from 'chai'; | ||
}); | ||
describe('list', () => { | ||
it('returns the list of groups', () => { | ||
const groups = createDisposables(); | ||
groups.registerGroup('first', { before: 'default' }); | ||
groups.add(() => void 0, { | ||
name: '1', | ||
group: 'first', | ||
timeout: 1, | ||
}); | ||
groups.add(() => void 0, { | ||
name: '2', | ||
group: 'first', | ||
timeout: 10, | ||
}); | ||
groups.add(() => void 0, { | ||
name: '3', | ||
timeout: 100, | ||
}); | ||
const list = groups.list(); | ||
expect(list.totalTimeout).to.eql(111); | ||
expect(list.groups).to.have.length(2); | ||
expect(list.groups[0]?.totalTimeout).to.eql(11); | ||
expect(list.groups[0]?.disposables).to.have.length(2); | ||
expect(list.groups[1]?.totalTimeout).to.eql(100); | ||
expect(list.groups[1]?.disposables).to.have.length(1); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
159175
2904