Skip to content

Conversation

@mzgoddard
Copy link
Contributor

  • Update commitlint dependencies
    The commitmsg command was erroring and so not letting me commit changes.
  • Replace async.waterfall with Promise chain
    scratch-parser is the only scratch package used by scratch-gui using the async module. We can save ~180KB of javascript by either using async-es, another similar package or promises. I didn't want to rewrite the commonjs modules into es modules so I opted for Promises.

@mzgoddard mzgoddard force-pushed the waterfall-into-promise branch from 82da898 to 593e123 Compare February 7, 2019 19:13
index.js Outdated
// applying this function?
.then(validate.bind(null, isSprite)),
toUnpack
.then(function (unpackedProject) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new structure seems a bit awkward now, maybe we can reorganize this code so that we have nested .thens? E.g. the other functions e.g. parse, validate, etc. live inside the .then for the unpack and then the last bit has access to the unpackedProject and can call the callbacks...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

I think what you described is nesting thens.

Promise.all([
    toUnpack
        .then(function (unpacked) {
            return parse(unpacked[0])
                .then(validate.bind(null, isSprite));
        }),
    toUnpack
        .then(function (unpacked) {
            return unpacked[1];
        })
])
    .then(callback.bind(null, null), callback);

How about:

unpack(input, isSprite)
    .then(function (unpacked) {
        return Promise.all([parse(unpacked[0]), unpacked[1]]);
    })
    .then(function (parsed) {
        return Promise.all([validate(isSprite, parsed[0]), parsed[1]]);
    })
    .then(callback.bind(null, null), callback);

I normally try to write promise functions that do not need external contexts. It probably doesn't matter here since it needs so few lines, but its a big help with large promise chain functions.

On that point what about:

unpack(input, isSprite)
    .then(function (unpackedProject) {
        return parse(unpackedProject[0])
            .then(validate.bind(null, isSprite))
            .then(function (validatedProject) {
                return [validatedProject, unpackedProject[1]];
            });
    })
    .then(callback.bind(null, null), callback);

Copy link
Contributor

@kchadha kchadha Feb 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mzgoddard, that last one is pretty much what I was trying to suggest. Sorry I should have been more clear.

Copy link
Contributor

@kchadha kchadha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code can probably be re-written to be a little easier to understand. I left a comment in the code review.

@kchadha
Copy link
Contributor

kchadha commented Feb 11, 2019

@mzgoddard should I be seeing an update to commitlint in the changed files? You mentioned it in the PR description but I don't see the related change..

@mzgoddard
Copy link
Contributor Author

@kchadha I believe I removed the commitlint thing in the https://github.com/LLK/scratch-parser/compare/82da89870420c1e83d96e9dab64d19d805cd7c78..593e12333881761e93b41a831f9a828d276fa9cc force push. The commitlint change was in develop so I rebased and and was able to drop that change.

@mzgoddard mzgoddard force-pushed the waterfall-into-promise branch from 593e123 to b78d017 Compare February 22, 2019 21:11
@mzgoddard
Copy link
Contributor Author

  • Change waterfall promise to one of the discussed possibilities

Copy link
Contributor

@kchadha kchadha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mzgoddard, thanks for making those changes. LGTM

@mzgoddard mzgoddard merged commit c5cc58e into scratchfoundation:master Mar 6, 2019
@mzgoddard mzgoddard deleted the waterfall-into-promise branch March 6, 2019 16:12
@kchadha
Copy link
Contributor

kchadha commented Mar 6, 2019

🎉 This PR is included in version 4.3.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants