Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
richytong committed Dec 15, 2024
1 parent 25979c9 commit 2042ad3
Show file tree
Hide file tree
Showing 334 changed files with 2,212 additions and 883 deletions.
2 changes: 1 addition & 1 deletion dist/Transducer.es.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion dist/Transducer.es.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/Transducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion dist/Transducer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/Transducer.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion dist/__.es.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion dist/__.es.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion dist/__.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion dist/__.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
2 changes: 1 addition & 1 deletion dist/__.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
Expand Down
115 changes: 107 additions & 8 deletions dist/all.es.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,82 @@
/**
* rubico v2.6.1
* rubico v2.6.2
* https://github.com/a-synchronous/rubico
* (c) 2019-2024 Richard Tong
* rubico may be freely distributed under the MIT license.
*/

const isPromise = value => value != null && typeof value.then == 'function'

const isArray = Array.isArray

const areAnyValuesPromises = function (values) {
const length = values.length
let index = -1
while (++index < length) {
const value = values[index]
if (isArray(values)) {
const length = values.length
let index = -1
while (++index < length) {
const value = values[index]
if (isPromise(value)) {
return true
}
}
return false
}

for (const key in values) {
const value = values[key]
if (isPromise(value)) {
return true
}
}
return false
}

const areAllValuesNonfunctions = function (values) {
if (isArray(values)) {
const length = values.length
let index = -1
while (++index < length) {
if (typeof values[index] == 'function') {
return false
}
}
return true
}

for (const key in values) {
if (typeof values[key] == 'function') {
return false
}
}
return true
}

const promiseAll = Promise.all.bind(Promise)

const isArray = Array.isArray
const promiseObjectAllExecutor = object => function executor(resolve) {
const result = {}
let numPromises = 0
for (const key in object) {
const value = object[key]
if (isPromise(value)) {
numPromises += 1
value.then((key => function (res) {
result[key] = res
numPromises -= 1
if (numPromises == 0) {
resolve(result)
}
})(key))
} else {
result[key] = value
}
}
if (numPromises == 0) {
resolve(result)
}
}

const promiseObjectAll = object => new Promise(promiseObjectAllExecutor(object))

const __ = Symbol.for('placeholder')

Expand Down Expand Up @@ -71,7 +126,8 @@ const functionArrayAll = function (funcs, args) {
result = Array(funcsLength)
let funcsIndex = -1, isAsync = false
while (++funcsIndex < funcsLength) {
const resultItem = funcs[funcsIndex](...args)
const f = funcs[funcsIndex]
const resultItem = typeof f == 'function' ? f(...args) : f
if (isPromise(resultItem)) {
isAsync = true
}
Expand Down Expand Up @@ -195,7 +251,8 @@ const always = value => function getter() { return value }
const functionObjectAll = function (funcs, args) {
const result = {}, promises = []
for (const key in funcs) {
const resultItem = funcs[key](...args)
const f = funcs[key]
const resultItem = typeof f == 'function' ? f(...args) : f
if (isPromise(resultItem)) {
promises.push(resultItem.then(curry3(objectSet, result, key, __)))
} else {
Expand All @@ -205,7 +262,48 @@ const functionObjectAll = function (funcs, args) {
return promises.length == 0 ? result : promiseAll(promises).then(always(result))
}

const _allValues = function (values) {
if (isArray(values)) {
return areAnyValuesPromises(values)
? promiseAll(values)
: values
}
return areAnyValuesPromises(values)
? promiseObjectAll(values)
: values
}

const all = function (...args) {
if (args.length == 1) {
const resolversOrValues = args[0]
if (isPromise(resolversOrValues)) {
return resolversOrValues.then(_allValues)
}
if (areAllValuesNonfunctions(resolversOrValues)) {
return _allValues(resolversOrValues)
}
return isArray(resolversOrValues)
? curryArgs2(functionArrayAll, resolversOrValues, __)
: curryArgs2(functionObjectAll, resolversOrValues, __)
}

const resolversOrValues = args[args.length - 1]
const argValues = args.slice(0, -1)

if (areAnyValuesPromises(argValues)) {
return isArray(resolversOrValues)
? promiseAll(argValues)
.then(curry2(functionArrayAll, resolversOrValues, __))
: promiseAll(argValues)
.then(curry2(functionObjectAll, resolversOrValues, __))
}

return isArray(resolversOrValues)
? functionArrayAll(resolversOrValues, argValues)
: functionObjectAll(resolversOrValues, argValues)

/*
////////////////////////////////////////////////////////////////
const funcs = args.pop()
if (args.length == 0) {
return isArray(funcs)
Expand All @@ -222,6 +320,7 @@ const all = function (...args) {
return isArray(funcs)
? functionArrayAll(funcs, args)
: functionObjectAll(funcs, args)
*/
}

all.series = function allSeries(...args) {
Expand Down
4 changes: 2 additions & 2 deletions dist/all.es.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2042ad3

Please sign in to comment.