Skip to content
This repository was archived by the owner on Jul 30, 2018. It is now read-only.

Convert Runner and Editor to widgets #14

Merged
merged 6 commits into from
Jun 15, 2017
Merged

Conversation

kitsonk
Copy link
Member

@kitsonk kitsonk commented May 23, 2017

Feature

The PR converts the Runner and Editor to widgets. It also makes a slight change to project where there is now a .getProgram() which returns a map of values which can be passed to the Runner for running the application. Previously this logic was integrated into Runner.

Resolves #6

@codecov
Copy link

codecov bot commented May 23, 2017

Codecov Report

Merging #14 into master will decrease coverage by 0.38%.
The diff coverage is 95.38%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #14      +/-   ##
=========================================
- Coverage   94.48%   94.1%   -0.39%     
=========================================
  Files          15      15              
  Lines         490     560      +70     
  Branches       86      96      +10     
=========================================
+ Hits          463     527      +64     
- Misses         27      33       +6
Impacted Files Coverage Δ
src/project.ts 87.67% <100%> (+0.71%) ⬆️
src/support/providers/amdRequire.ts 100% <100%> (ø) ⬆️
src/Editor.ts 93.87% <92.85%> (-6.13%) ⬇️
src/Runner.ts 97.63% <94.54%> (-2.37%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3286d9f...ad8a42f. Read the comment docs.

@kitsonk
Copy link
Member Author

kitsonk commented May 23, 2017

This is obviously a big PR. The main focus should be on the examples/index.ts to see how a basic sort of application is built using the Runner and Editor widgets.

dylans
dylans previously requested changes May 24, 2017
Copy link
Member

@dylans dylans left a comment

Choose a reason for hiding this comment

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

Minor nits... I focused mostly on typos rather that code changes.

README.md Outdated
display files with the appropriate language intellisense as well as the file is edited, changes will automatically be sent to
the project to keep it updated.

The `Editor` constructor takes two arguments. First, you need to provide a DOM element that will serve as the root for the editor.
The second is an optional argument is a pass through of any options as specified in the `monaco.editor.IEditorOptions` interface.
The `Editor` properties have two key properties:
Copy link
Member

Choose a reason for hiding this comment

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

"The Editor properties have two key properties:" -> "The Editor has two key properties:" ?

README.md Outdated

The class has only one method:
* `filename` - This is the name of the file in the project which the editor should be displaying.
Copy link
Member

Choose a reason for hiding this comment

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

"This is the name of the file in the project which the editor should be displaying." -> "Name of the file in the project which the editor should display."

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, this one I debated, as like with widgets, you have to always set the properties. So conditional future tense is not quite appropriate, but I get the point that it could be phrased better.

README.md Outdated
})();
```

### Runner

This is a class which provides a simple API to run instances of a project within an `iframe` on a page. It will automatically
transpile the project and send the transpiled output to the `iframe`.
This is a widget which can _run_ a program in an `iframe`. Updating the properties related to the program on the widget will
Copy link
Member

Choose a reason for hiding this comment

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

"This is a widget which" -> "A widget which"

README.md Outdated

The `Runner` constructor takes a single arugment, which is the `iframe` it should use to run the project in.
The `Runner` has several key properties which control its behaviour:
Copy link
Member

Choose a reason for hiding this comment

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

behaviour -> behavior (for consistency)

README.md Outdated

The class has one method of note:
* `css`, `dependencies`, `html`, and `modules` - Propties that a are part of a `Program` obtained from the returned promise of
Copy link
Member

Choose a reason for hiding this comment

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

"Propties that a are part of " -> "Properties that are part of "

README.md Outdated
`project.getProgram()`.
* `loader` - An optional property which specifies the URI for the AMD loader to use with the program. It defaults to the latest
version of the `@dojo/loader`.
* `src` - Is an optional URI that will be the `src` of the `iframe` until a program is first run. This needs to be a relative URI
Copy link
Member

Choose a reason for hiding this comment

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

"Is an optional" -> "An optional"

src/Editor.ts Outdated
* A class which is a simple abstraction of the `monaco-editor` editor
* @type EditorProperties
*
* Properties that can be set on Editor widget
Copy link
Member

Choose a reason for hiding this comment

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

"on Editor widget" missing word, either an or the?

src/Runner.ts Outdated
* @property src A URI that points to the `src` to set on the Runner's `iframe`. Defaults to
* `../support/blank.html`
* @property onError A method that will be called whenever there is an error in the running program
* @property onInitIframe A method that will be called when the `iframe` is initiailized
Copy link
Member

Choose a reason for hiding this comment

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

initiailized -> initialized

@@ -118,6 +145,50 @@ function getPackages(dependencies: { [pkg: string]: string; }): string[] {
}

/**
* Generate an HTML page which represents the Runner properties
* @param param0 Properties from the Runner to be used to specify the document
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar with the param0 syntax. If that is correct, ignore me, and if not, then of course fix it.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is what the TypeScript services stubs out. There is an open issue to actually support it, as I don't think TypeScript does at the moment.

@dylans dylans added this to the 2017.05 milestone May 24, 2017
Copy link
Member

@agubler agubler left a comment

Choose a reason for hiding this comment

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

Just a few nits and questions :)

src/Editor.ts Outdated
export interface EditorProperties extends WidgetProperties, ThemeableProperties {
filename?: string;
options?: monaco.editor.IEditorOptions;

Copy link
Member

Choose a reason for hiding this comment

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

nit: why the blank line?

Copy link
Member Author

Choose a reason for hiding this comment

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

well, they were methods, and not necessairly in order of the previous properties. We have been putting them at the end of properties but I felt if I wan't going to order them alphabetically a new line would be a better visual indication of the "sectioning" of them.

src/Editor.ts Outdated

/* tslint:disable:variable-name */
Copy link
Member

Choose a reason for hiding this comment

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

We have actually changed the rule for variable names for this usage in Dojo 2

Copy link
Member Author

Choose a reason for hiding this comment

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

I will update the tslint

src/Editor.ts Outdated
}));
public render() {
return v('div', {
afterCreate: this._initEditor,
Copy link
Member

Choose a reason for hiding this comment

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

Word of warning, afterCreate and afterUpdate are going to be removed from the VirtualDomProperties interface in a future release of widget-core.

Potentially better to use the currently exposed hooks onElementCreated and onElementUpdated in any case.

src/Editor.ts Outdated
if (!project.includes(filename)) {
throw new Error(`File "${filename}" is not part of the project.`);
@afterRender()
public updateEditor(node?: DNode): DNode | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

Seems odd to use this as an afterRender and also the function to attach to the afterUpdate hook.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was exactly the same code... I could move it to a totally private method and then call it from the two locations, but it seemed odd as well.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm yeah, why does the same code to run in an afterRender and then again on an afterUpdate?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at it, I have no f*ing idea what I did that... 😢

export interface RunnerProperties extends Partial<Program>, WidgetProperties, ThemeableProperties {
loader?: string;
src?: string;

Copy link
Member

Choose a reason for hiding this comment

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

Okay same question re line break but I think I see the pattern now separating values and functions.

src/Runner.ts Outdated
public render() {
return v('div', {
classes: this.classes(css.base)
}, [ v('iframe', {
Copy link
Member

Choose a reason for hiding this comment

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

Would this be a candidate to for the element being explicitly created in the constructor (so we have a handle on the element) and then using the DomWrapper wrap it and include in the tree?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be a way of doing it. Are there really and advantages? The virtual DOM is just as good at creating and element as a constructor function. In addition, there are potentially other advantages with what we have been doing with subsuming DOM in the projector. The widget doesn't really care how the iframe gets there.

Copy link
Member

Choose a reason for hiding this comment

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

It means you don't need to "get" the element from widget system - which could be advantageous once those hooks have been removed.

Perhaps could then restructure the way the "afterCreate", "afterUpdate" functionality works also.

fileSelect = v('div', { key: 'fileSelect' }, [
v('div', [
v('label', { for: 'select-file' }, [ 'File to display:' ]),
v('select', { name: 'select-file', id: 'select-file', onchange: this._onchangeFile }, this._getFileOptions())
Copy link
Member

Choose a reason for hiding this comment

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

could use the Dojo 2 widget potentially

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about it. I wanted to take care of it when I did #9 as right now, it would be painful to include the CSS for the other widget. I already have to explicitly include the Runner and Editor CSS.

@eheasley eheasley modified the milestones: 2017.05, 2017.06 Jun 6, 2017
@kitsonk kitsonk dismissed dylans’s stale review June 15, 2017 23:09

Issues addressed

@kitsonk kitsonk merged commit 1a063c2 into dojo:master Jun 15, 2017
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.

4 participants