Skip to content

Conversation

@ning-y
Copy link
Member

@ning-y ning-y commented May 16, 2018

Addresses #2, 'Scaffold Playground Layout'.

  • Playground is a child of application
  • Playground is associated with new state IPlaygroundState which is a child of IState
  • IPlaygroundState stores the contents of the playground editor, allowing it to persist between pages
  • Use the library react-ace to implement the editor

ning-y and others added 26 commits May 14, 2018 10:48
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
@remo5000 remo5000 added the Enhancement New feature request label May 16, 2018
@remo5000 remo5000 added this to the Sprint 1 milestone May 16, 2018
@remo5000 remo5000 requested a review from evansb May 16, 2018 04:25
import { IUpdateEditorValue, UPDATE_EDITOR_VALUE } from '../actions/playground'

/**
* A state for the playground container
Copy link

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?

Copy link
Contributor

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.

* @property newEditorValue - The new string value for `editorValue`
*/
export interface IUpdateEditorValue extends Action {
type: string
Copy link

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

*/
export interface IUpdateEditorValue extends Action {
type: string
newEditorValue: string
Copy link

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.

Copy link
Contributor

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.

}

const Application: React.SFC<IApplicationProps> = ({ application }) => {
const Application: React.SFC<IApplicationProps> = (props: IApplicationProps) => {
Copy link

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.

Copy link
Contributor

@remo5000 remo5000 May 16, 2018

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?

* The `type` attribute for an `Action` which updates the `IPlaygroundState`
* `editorValue`
*/
export const UPDATE_EDITOR_VALUE: string = 'UPDATE_EDITOR_VALUE'
Copy link

Choose a reason for hiding this comment

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

string is redundant

Copy link

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

*/
export interface IPlaygroundProps {
editorValue: string
updateCode: (newCode: string) => void
Copy link

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

/**
* A component representing the Playground
*/
export default class Playground extends React.Component<IPlaygroundProps, {}> {
Copy link

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

Copy link
Contributor

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?

Copy link

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

Copy link
Contributor

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!

remo5000 and others added 6 commits May 16, 2018 23:38
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.
@evansb evansb merged commit e7a64b9 into master May 18, 2018
@ning-y ning-y deleted the scaffold-playground branch May 18, 2018 10:00
gerhean added a commit that referenced this pull request Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants