-
Notifications
You must be signed in to change notification settings - Fork 174
Scaffold playground page #8
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
Conversation
No functionality.
Changes: - Changed `Playground` component to a statefull one (extends `React.Component) - add property `playgroundCode` to IApplicationState (bad practice, change to a slice of the state instead) - add interface `IPlaygroundProps` to denote the properties passed to Playground
Once again, this is a WIP. Text typed into the playground editor will stay in the playground (or rather, appear again) after leaving and coming back. Changes: - added of action, actionCreator (updatePlaygroundCode) - added a reducer under application's `reducer` function Possible problems: - Location of reducer - Location of playgroundCode stored (as in previous commit)
Made a compromise by including an IPlaygroundState as part of IApplicationProps
src/reducers/playground.ts
Outdated
| import { IUpdateEditorValue, UPDATE_EDITOR_VALUE } from '../actions/playground' | ||
|
|
||
| /** | ||
| * A state for the playground container |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, since we have established a convention, I think the comment can be terser and only to describe non-obvious name or to explain a complex routine/function.
I think we can go with no comment by default, the reviewer will be the one responsible for requesting documentation if deemed necessary, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with removing it for now, and add it later on if necessary. For now, the properties and name do seem to be sufficiently self-explanatory.
src/actions/playground.ts
Outdated
| * @property newEditorValue - The new string value for `editorValue` | ||
| */ | ||
| export interface IUpdateEditorValue extends Action { | ||
| type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be redundant, all Action is expected to have a type field, please verify
src/actions/playground.ts
Outdated
| */ | ||
| export interface IUpdateEditorValue extends Action { | ||
| type: string | ||
| newEditorValue: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should follow the Redux FSA(Flux Standard Action) convention. The payload of the action should be under the name payload. A payload is typically an object in complex action, but in this case I think a string suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, do you mean the naming convention only? Or do you mean that we should keep thepayload object as an arbitrarily typed object (like in most example online)? I feel that the typing should remain strict for a particular payload.
src/components/Application.tsx
Outdated
| } | ||
|
|
||
| const Application: React.SFC<IApplicationProps> = ({ application }) => { | ||
| const Application: React.SFC<IApplicationProps> = (props: IApplicationProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding IApplicationProps after props: is redundant because we already declare the type as React.SFC<IApplicationProps>. TypeScript is able to infer the parameter type. So you can unpack { title } straight away in the parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it would be better to keep a props argument as compared to unpacking it to { title }, so that adding properties to IApplicationProps does not require an additional change in the arguments. What do you think?
src/actions/playground.ts
Outdated
| * The `type` attribute for an `Action` which updates the `IPlaygroundState` | ||
| * `editorValue` | ||
| */ | ||
| export const UPDATE_EDITOR_VALUE: string = 'UPDATE_EDITOR_VALUE' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When in doubt, you can check with your editor /IDE, if upon hovering to the variable you see a type, that means the type can be inferred.
Of course sometimes you want to explicitly declare it anyway, for documentation purposes
src/components/Playground.tsx
Outdated
| */ | ||
| export interface IPlaygroundProps { | ||
| editorValue: string | ||
| updateCode: (newCode: string) => void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually the convention for event handler begins with handle<event-name>, i.e handleEditorChange
src/components/Playground.tsx
Outdated
| /** | ||
| * A component representing the Playground | ||
| */ | ||
| export default class Playground extends React.Component<IPlaygroundProps, {}> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should always default to React.SFC until you need state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, our editor would need to call upon a dispatch to update the editorValue within the IPlaygroundState, whenever someone edits code in the ace editor. Is a Component warranted in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, so in this case the editor component is stateful, but the playground component itself should be stateless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I understand now. Will do!
Changes not made: - Change of `Playground` component to an `SFC`
This is done by abstracting out the ace editor into its own component , `Editor`, and its own container to handle redux calls, `EditorContainer`.
Export of `Editor` changed to a default export, like the other components. A test has been added for the `Editor` component. Snapshot changes pending.
Addresses #2, 'Scaffold Playground Layout'.
IPlaygroundStatewhich is a child ofIStateIPlaygroundStatestores the contents of the playground editor, allowing it to persist between pagesreact-aceto implement the editor