Merge pull request 'allow calling all multiple times' (#1417) from multiple-all-calls into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1417
This commit is contained in:
commit
860bb58d61
1 changed files with 7 additions and 3 deletions
|
|
@ -113,8 +113,9 @@ export function repl({
|
||||||
* all(x => x.pianoroll())
|
* all(x => x.pianoroll())
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
let allTransforms = [];
|
||||||
const all = function (transform) {
|
const all = function (transform) {
|
||||||
allTransform = transform;
|
allTransforms.push(transform);
|
||||||
return silence;
|
return silence;
|
||||||
};
|
};
|
||||||
/** Applies a function to each of the running patterns separately. This is intended for future use with upcoming 'stepwise' features. See `all` for a version that applies the function to all the patterns stacked together into a single pattern.
|
/** Applies a function to each of the running patterns separately. This is intended for future use with upcoming 'stepwise' features. See `all` for a version that applies the function to all the patterns stacked together into a single pattern.
|
||||||
|
|
@ -190,6 +191,7 @@ export function repl({
|
||||||
await injectPatternMethods();
|
await injectPatternMethods();
|
||||||
setTime(() => scheduler.now()); // TODO: refactor?
|
setTime(() => scheduler.now()); // TODO: refactor?
|
||||||
await beforeEval?.({ code });
|
await beforeEval?.({ code });
|
||||||
|
allTransforms = []; // reset all transforms
|
||||||
shouldHush && hush();
|
shouldHush && hush();
|
||||||
let { pattern, meta } = await _evaluate(code, transpiler, transpilerOptions);
|
let { pattern, meta } = await _evaluate(code, transpiler, transpilerOptions);
|
||||||
if (Object.keys(pPatterns).length) {
|
if (Object.keys(pPatterns).length) {
|
||||||
|
|
@ -202,8 +204,10 @@ export function repl({
|
||||||
} else if (eachTransform) {
|
} else if (eachTransform) {
|
||||||
pattern = eachTransform(pattern);
|
pattern = eachTransform(pattern);
|
||||||
}
|
}
|
||||||
if (allTransform) {
|
if (allTransforms.length) {
|
||||||
pattern = allTransform(pattern);
|
for (let i in allTransforms) {
|
||||||
|
pattern = allTransforms[i](pattern);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!isPattern(pattern)) {
|
if (!isPattern(pattern)) {
|
||||||
const message = `got "${typeof evaluated}" instead of pattern`;
|
const message = `got "${typeof evaluated}" instead of pattern`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue