Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More selectors #2500

Merged
merged 5 commits into from Feb 8, 2018
Merged

More selectors #2500

merged 5 commits into from Feb 8, 2018

Conversation

theengineear
Copy link
Contributor

@theengineear theengineear commented Feb 7, 2018

Jumping on the selectors train! I want to start moving state around, but I won't be confident about doing that until we centralize access with these selectors.

Couple questions:

  1. naming: holy getCurrent*, batman! It's a little wordy! Maybe current should be the default thing we assume to be getting when we're using selectors.
  2. notificationStystem stuff: not touching it, it's like an object with methods on it? I'm just going to assume we're not moving that :0
  3. putting selectors to work: since we're memoizing, we might as well make selectors that do all the work for us! One example here is the getCurrentCodeCellIdsBelow (i know, a mouthful...). you're on board for more of the same, right?
  4. In general, we should try and keep selectors as specific as possible. The more general they are, the less we can change state! I.e., selectors should be a black box. We should never return hunks of state that we think we'd want to refactor the internals of. Ya?

@rgbkrk
Copy link
Member

rgbkrk commented Feb 7, 2018

naming: holy getCurrent*, batman! It's a little wordy! Maybe current should be the default thing we assume to be getting when we're using selectors.

current* is way better than getCurrent*, especially since every selector is a get*.

@@ -8,7 +8,7 @@ import {

import { overwriteMetadata, deleteMetadata } from "@nteract/core/actions";

import { toJS, stringifyNotebook } from "@nteract/commutable";
import * as selectors from "@nterat/core/selectors";
Copy link
Member

Choose a reason for hiding this comment

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

from "@nteract/core/selectors"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤣

notebook.getIn(["metadata", "github_username"]) !==
(res.data.login || undefined)
) {
if (githubUsername !== (res.data.login || undefined)) {
Copy link
Member

Choose a reason for hiding this comment

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

solid cleanups in here

@theengineear
Copy link
Contributor Author

current* is way better than getCurrent*, especially since every selector is a get*.

Cool. Accepted 😎.

We will commonly be naming variables with the same name as the selector.
Instead of doing variable gymnastics, we can just import selectors in
a namespace.
You're always *getting* with selectors, so this is a little excessive.
dummyCommutable,
dummy,
"fake-github-username",
"fake-gist-id",
"./test.ipynb",
notificationSystem,
false,
Copy link
Member

Choose a reason for hiding this comment

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

This should all make @jdetle happy! 🎉

const serverUrl = (state: AppState) => state.app.host.serverUrl;
const crossDomain = (state: AppState) => state.app.host.crossDomain;
const token = (state: AppState) => state.app.host.token;

export const getServerConfig = createSelector(
export const serverConfig = createSelector(
Copy link
Member

Choose a reason for hiding this comment

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

👍


const identity = thing => thing;
Copy link
Member

Choose a reason for hiding this comment

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

heh


import { createSelector } from "reselect";
import { toggleCellInputVisibility } from "../../actions";
Copy link
Member

Choose a reason for hiding this comment

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

How'd an action sneak in here?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this didn't mean to be here

(hostType, kernelType) => {
return hostType === "jupyter" && kernelType === "websocket";
}
);

// TODO: if we're not looking at a notebook in the UI, there may not _be_ a
// notebook object to get. Do we return null? Throw an error?
Copy link
Member

Choose a reason for hiding this comment

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

I think null is fine

Copy link
Member

Choose a reason for hiding this comment

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

That or emptyNotebook (from commutable)

export const currentNotebookGithubUsername = createSelector(
[currentNotebook],
notebook => notebook.getIn(["metadata", "github_username"])
);
Copy link
Member

Choose a reason for hiding this comment

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

Since we're having to put the selectors here for the github functionality, we might as well move the reducer from desktop's app reducer (and maybe the epic...). Not for this PR, but it'll be nice for desktop to have no custom reducers now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, didn't even realize that these were being set in desktop.

.skip(index)
.filter(id => cellMap.getIn([id, "cell_type"]) === "code");
}
);
Copy link
Member

Choose a reason for hiding this comment

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

At some point we'll want to re-evaluate how we do run-all and run-all-below, since they belong in an epic that tracks the execution rolling on through.

return action$.pipe(
ofType(SAVE_AS),
mergeMap(action => {
const state = store.getState();
const notebook = state.document.get("notebook");

Copy link
Member

Choose a reason for hiding this comment

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

Ooooohhhh cool, we didn't need the notebook here anymore.

@rgbkrk
Copy link
Member

rgbkrk commented Feb 8, 2018

Separately, we should extract getCodeMirrorMode out as a selector too: https://github.com/nteract/nteract/blob/master/packages/core/src/providers/notebook-app.js#L295

@rgbkrk
Copy link
Member

rgbkrk commented Feb 8, 2018

We'll probably want to switch a lot of our mapStateToProps to using these as well.

state.document.get("notebook"),
state.document.get("savedNotebook")
selectors.currentNotebook(state),
selectors.currentSavedNotebook(state)
);
Copy link
Member

@rgbkrk rgbkrk Feb 8, 2018

Choose a reason for hiding this comment

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

This could be an isSaved selector.

@rgbkrk rgbkrk merged commit 1e8426e into nteract:master Feb 8, 2018
@rgbkrk rgbkrk added this to the Jupyter Extension M1 milestone Feb 10, 2018
@rgbkrk rgbkrk mentioned this pull request Mar 7, 2018
7 tasks
@lock
Copy link

lock bot commented May 1, 2018

Howdy! I'm 🔓🤖!

In order to keep information timely (based on the most recent release), we want all activity to be added to either new issues or open issues and PRs. In service to that goal, I, the lock bot close inactive closed issues when they haven't had activity in 120 days.

Feel free to open a new issue for related bugs and link to relevant comments from this thread.

@lock lock bot locked and limited conversation to collaborators May 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants