let merger = {
molds: 'molds',
groups: 'groups'
}
import { Merger } from 'packhouse/types'
let merger: Merger = {}
const group = {
tools: {
sum: {
request: ['myMerger@int', 'myMerger@int'],
handler(self, v1, v2) {
self.success(v1 + v2)
}
}
}
}
const merger = {
molds: {
int(value) {
return Math.floor(value)
}
}
}
packhouse.merger('myMerger', merger)
packhouse.addGroup('math', group)
packhouse.tool('math/sum').action(1.1, 2.5, (err, result) => {
console.log(result) // 3
})
const group = {
tools: {
sum: {
handler(self, v1, v2) {
self.success(v1 + v2)
}
}
}
}
const merger = {
groups: {
math(options) {
console.log(options.PI) // 3.14159...
return {
data: group
}
}
}
}
packhouse.merger('myMerger', merger, {
PI: Math.PI
})
packhouse.tool('myMerger@math/sum').action(...)
let group1 = {
tools: {
sum: {
handler(self, v1, v2) {
self.success(v1 + v2)
}
}
}
}
let group2 = {
mergers: {
mySumGroup: 'sumGroup'
},
tools: {
double: {
install({ include }) {
include('sum').tool('mySumGroup/sum')
},
handler(self, v1) {
self.tool('sum').action(v1, v1, (e, r) => {
self.success(r)
})
}
}
}
}
let merger = {
groups: {
sumGroup() {
return {
data: group1
}
},
doubleGroup() {
return {
data: group2
}
}
}
}
packhouse.merger('myMerger', merger)
packhouse.tool('myMerger@doubleGroup/double').action(10, (e, r) => {
console.log(r) // 20
})