Skip to content

Validates source on project creation, closes #1257#1269

Merged
outoftime merged 1 commit into
popcodeorg:masterfrom
alessbell:bugfix/1257-console-expressions-not-evaluated
Dec 12, 2017
Merged

Validates source on project creation, closes #1257#1269
outoftime merged 1 commit into
popcodeorg:masterfrom
alessbell:bugfix/1257-console-expressions-not-evaluated

Conversation

@alessbell

Copy link
Copy Markdown
Contributor

This PR closes issue 1257.

It's also my first Popcode PR 🎉 Validating the source on project creation made sense to me but feedback is welcome as I learn more about the code base :)

Comment thread src/sagas/projects.js Outdated

export function* createProject() {
yield put(projectCreated(generateProjectKey()));
yield put(validatedSource('javascript', []));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So this approach definitely works, but kind of as a second-order effect, because the compiledProjects saga consumes this action and initiates compilation in response to it.

My preference is to keep action dispatches as close as possible to an unvarnished record of what actually happened (somebody clicked a button, some async operation finished, etc.) In this case we are saying we’ve finished validating a source, but in fact we haven’t (this intuition is strengthened, I think, by the fact that we have to arbitrarily pick a language to say we have validated).

My proposal would be: instead of adding a new dispatch into the flow, simply make the system react more robustly to the actions that are already being dispatched. In particular, I think the compiledProjects saga should consume the PROJECT_CREATED action and compile the project in response.

LMK what you think!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, makes sense! This solution indeed felt slightly wrong with the language hard-coded.

The thinking was that, given that the source is a brand new Popcode, it can safely be assumed valid. I was after that second-order effect :) Much clearer to simply compile the project, updated.

Comment thread src/sagas/compiledProjects.js Outdated
yield all([throttle(100, 'VALIDATED_SOURCE', validatedSource)]);
yield all([
throttle(100, 'VALIDATED_SOURCE', validatedSource),
takeEvery('APPLICATION_LOADED', validatedSource),

@outoftime outoftime Dec 12, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is fairly inside baseball, but I think we actually want to consume PROJECT_CREATED here—APPLICATION_LOADED will trigger different behavior in the projects saga depending on the initial application state (snapshot/gist ID in the URL, project rehydrated from local storage, etc.), and in some circumstances the saga will kick off a full validation. The case when it doesn’t do a full validation is exactly the case when it dispatches PROJECT_CREATED.

As a bonus, that’ll makes the console work right after you click “New Project”, which it currently does not—a closely related bug!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops! Right yes makes sense, tho didn't realize that re: "New Project"

@outoftime outoftime left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now we’re cooking with gas!!

@outoftime outoftime merged commit c5e4785 into popcodeorg:master Dec 12, 2017
@alessbell alessbell deleted the bugfix/1257-console-expressions-not-evaluated branch December 12, 2017 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Console expressions not evaluated in freshly loaded environment

2 participants