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

Migrating away from AngularJS #16

Merged
merged 26 commits into from
Sep 14, 2017
Merged

Migrating away from AngularJS #16

merged 26 commits into from
Sep 14, 2017

Conversation

AmitMY
Copy link
Contributor

@AmitMY AmitMY commented Sep 7, 2017

Removing the dependency in AngularJS, moving to custom elements in ES6 and SCSS, more tests, tests coverage, better files structure.

BLOG.md files is the work in progress blog post to release after merging. It contains all the information on what was done.

Fixes:
#2 - Adds a readyEvent Event emitter, whenever it redraws (new SVG)
#4 - Using an event emitter, can unsubscribe

Like everything, this needs many many many more tests, as the main provider is not fully covered.

@AmitMY AmitMY requested a review from ramtob September 7, 2017 06:40
Copy link
Member

@ramtob ramtob left a comment

Choose a reason for hiding this comment

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

Great job. I entered several questions, comments, and requests for small changes.

@@ -0,0 +1,49 @@
# Revisiting Force-Horse: Making a Legacy Plugin Agnostic and Usable
Copy link
Member

Choose a reason for hiding this comment

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

A very nice blog post and plan. A small point: it seems an exaggeration to call force-horse a "legacy" plugin. It is not that old.. it is just that javascript is developing so fast. I probably wrote it just before ES6 kicked in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!
It is legacy, just because AngularJS is legacy, see:

Legacy code refers to an application system source code type that is no longer supported

Yeah, you kind of mixed some ES6 in there, just a bit.

BLOG.md Outdated
While you can read all of the details on the library in Ram's [blog post](http://webiks.com/force-horse-force-layout-component/), the gist of it is having a library that adapts to many types of data sets, and is easily modifiable for the users, having many modes for nodes, D3.js forces, multiple edges between nodes, supporting any size of data set, and easily allowing customization of the base SVG's design.

## So... What's New?
Having the library written using AngularJS, forces the user to use a deprecated framework. Either the user thinks they can just include AngularJS in the bundle, increasing the bundle, or trying to implement the component for their used framework.
Copy link
Member

Choose a reason for hiding this comment

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

A small comment: AngularJS is, of course, not the front version of Angular, but it is not deprecated. It will be with us perhaps for a long time still..

README.md Outdated
@@ -68,38 +100,37 @@ The config parameters are:
}
```

The forceHorse project contains a complete **demo application**. The demo application is also available on the [plunker](http://embed.plnkr.co/SYmehtaAnQVyMpLJJY2B/?show=preview) site.
The forceHorse project contains a complete **demo application**. The demo application is also available on the [plunker](http://embed.plnkr.co/SYmehtaAnQVyMpLJJY2B/?show=preview) site.
Copy link
Member

Choose a reason for hiding this comment

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

The demo on plunker is probably out of date

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hahaha probably.
I'll make a new one on the updated code base, as the package is on NPM already (had to test it for the demo)

@@ -0,0 +1,63 @@
import {ForceHorseProvider} from '../../providers/force-horse';
Copy link
Member

Choose a reason for hiding this comment

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

It seems that you have three files with the same name force-horse.js (in different folders). This does not seem to me a good practice. Files tend to travel between folders. Better to have a unique name for each file, like force-horse-component.js, force-horse-helper.js, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reasonable. Done

/**
* Produces a class-instance for each instance of ForceHorse on a page
*/
export class ForceHorseProvider {
Copy link
Member

Choose a reason for hiding this comment

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

Why "provider" in the class name? Why not "factory" as it was before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it does not instantiate a service, and just provides logic for the component. Can change if you find this awful

use: extractSASS.extract({ // Instance 2
use: [
'css-loader',
'postcss-loader',
Copy link
Member

Choose a reason for hiding this comment

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

Why both postcss loader and sass loader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I use scss, and because I want autoprefixer for -webkit-mask.., so sass-loader for scss, and postcss for autoprefixer

@@ -0,0 +1,23 @@
language: node_js
Copy link
Member

Choose a reason for hiding this comment

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

I am not so familiar with Travis. What does this file do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every commit, travis will automatically try to tests. and report back on github what is the status
If there is a new tag, it will deploy it to a github release, and to an NPM release, hopefully

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See below, it shows a PR status

BLOG.md Outdated
While you can read all of the details on the library in Ram's [blog post](http://webiks.com/force-horse-force-layout-component/), the gist of it is having a library that adapts to many types of data, is easily modifiable for developers, supports large data sets, and easily allowing customization of the base SVG's design.

## So... What's New?
Having the library written using AngularJS, forces the user to use a deprecated framework. Either the user thinks they can just include AngularJS in the bundle, increasing the bundle, or trying to implement the component for their used framework.
Copy link
Member

Choose a reason for hiding this comment

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

AngularJS is not, strictly speaking, deprecated. It is still supported, and widely used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. Changed from "deprecated" to "legacy".

BLOG.md Outdated
Therefore, we decided to remove the dependency for AngularJS, making the library framework agnostic.

##### Agnostification
We migrated AngularJS out of the library, moving to a standard browser feature - [Custom Elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements), supported by most modern browsers, or being worked on at this time (In case it isn't supported, there is a tiny [browser polyfill](https://github.com/webcomponents/webcomponentsjs) - see [browsers support](https://caniuse.com/#search=custom%20elements%20v0))
Copy link
Member

Choose a reason for hiding this comment

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

  1. Actually you seem to have used here Custom Elements V1, which is not yet (as of 09.17) supported by most modern browsers.
  2. The link to caniuse.com needs to be fixed (V1)
  3. Can we ship the polyfill inside our package? (and, say, check whether the browser supports custom elements V1, and if not, automatically load the polyfill)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Done
  2. Done
  3. We can, we shan't imo. It is super simple to add, I can add the code to the README, it is like:
  • npm i @webcomponents/custom-elements
  • Add <script src="custom-elements.min.js"></script> or import from '@webcomponents/custom-elements/custom-elements.min.js'

The reason I think we shan't is that if you use Angular or React or whatever, it is just bloat.

@ramtob
Copy link
Member

ramtob commented Sep 14, 2017

It looks fine, I'm just still a bit uncomfortable with the word "provider"... Did you see the word "provider" used in this way anywhere else? I know the word is used in AngularJS, but it has a different meaning there (a kind of service generator). What do you think about "viewer" instead? Because what you called the force horse "component" is actually a container, wrapping the graph viewer (what you called "provider") and the buttons bars.

@AmitMY
Copy link
Contributor Author

AmitMY commented Sep 14, 2017

@ramtob Ok, done.
I also moved data and config to be attributes instead of options, as it makes more sense in an operative stand point, and added Angular integration in the README

@ramtob
Copy link
Member

ramtob commented Sep 14, 2017

Good. Just one more little request: instead of forceHorse.instance and this.instance, call it forceHorce.viewer and this.viewer. This will be more informative and readable (this.instance is actually a kind of duplication, since "this" is already an indication for an instance)

@AmitMY
Copy link
Contributor Author

AmitMY commented Sep 14, 2017

@ramtob Fair point, changed that.
Plunker/Demo apps will be up after your PR approval

@ramtob ramtob merged commit 73e7de0 into master Sep 14, 2017
@ramtob
Copy link
Member

ramtob commented Sep 14, 2017

I approved the PR. Nice work

@AmitMY
Copy link
Contributor Author

AmitMY commented Sep 14, 2017

Thanks!

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.

2 participants