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

[BREAKING CHANGE] Replace constructor function to class declaration #30

Merged
merged 4 commits into from
Jul 25, 2019

Conversation

segayuu
Copy link
Contributor

@segayuu segayuu commented Oct 8, 2018

No description provided.

@segayuu segayuu requested a review from a team October 8, 2018 04:50
Copy link
Contributor

@tcrowe tcrowe left a comment

Choose a reason for hiding this comment

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

@segayuu

In the future please provide:

  • a description and reasoning
  • how to test

We should also include something like this in a PR template across the repos where there is time.

For example:

It changes all the modules to use ES6 class-syntax instead of mimicking classes using prototypal inheritance. The reason we can do this without babel is because we're targeting >[email protected] in ./package.json.

How to test:

git clone -b replace-class https://github.com/segayuu/warehouse.git
cd warehouse
npm install
npm test

@tcrowe
Copy link
Contributor

tcrowe commented Oct 8, 2018

I found a problem integrating it with https://github.com/hexojs/hexo.

git clone -b replace-class https://github.com/segayuu/warehouse.git
cd warehouse
npm install
cd ..
git clone https://github.com/hexojs/hexo.git
cd hexo
npm install
npm rm warehouse
npm install ../warehouse
npm test

The result is this error:

TypeError: Class constructor SchemaType cannot be invoked without 'new'
    at new SchemaTypeMoment (hexo/lib/models/types/moment.js:8:14)
    at getSchemaType (warehouse/lib/schema.js:90:10)
    at Schema.path (warehouse/lib/schema.js:118:18)
    at Schema.add (warehouse/lib/schema.js:78:10)
    at new Schema (warehouse/lib/schema.js:56:12)
    at Object.module.exports.ctx [as Page] (hexo/lib/models/page.js:9:16)

@segayuu Maybe you can advise me here. Unless I did something wrong we may need to adjust other modules for compatibility.

@segayuu
Copy link
Contributor Author

segayuu commented Oct 9, 2018

I appreciate @tcrowe 's review!

This error message is not a bug.
The constructor generated by class declaration or class expression can not use SuperClass.call() equivalent to super().
For this reason, if the base class is defined with a class declaration or the like, derived classes will not be able to inherit classes in ES5 style.
Due to that influence, the number of change files of this PR has become very large.

Either way, the SchemaType class and its derived classes are assumed to inherit from the outside.
If emphasis is placed on compatibility, that class group will not be able to switch to the class declaration.

@yoshinorin
Copy link
Member

@tcrowe @segayuu

I think, following procedure is better way for migrate warehouse repository to class declaration.

  • Migrate this ripository sorce code to class declaration (this PR)
  • Warehouse package's versionup (major verup) and publish to npm
    • Also announce or write readme about breaking change.
  • Update hexo main repo's warehouse package version and fix related code.

I think hexo's core repositories should to be migrate ES6 step by step.

@segayuu
Copy link
Contributor Author

segayuu commented Oct 19, 2018

Ten days have passed since the last comment, and there are reactions with pictograms, so I will change the README.md and request a review again.

@segayuu segayuu changed the title Replace constructor function to class declaration [BREAKING CHANGE] Replace constructor function to class declaration Oct 19, 2018
 - Writing a text page assuming that major version upgrade was done.
@segayuu segayuu requested a review from a team October 19, 2018 02:57
Copy link
Contributor

@tcrowe tcrowe left a comment

Choose a reason for hiding this comment

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

I tested it and it works well. Thank you, @segayuu @yoshinorin 👍

@yoshinorin yoshinorin added this to the v3.0.0 milestone Jun 25, 2019
@segayuu segayuu merged commit 34399c5 into hexojs:master Jul 25, 2019
@segayuu segayuu deleted the replace-class branch July 25, 2019 05:01
segayuu added a commit to segayuu/warehouse that referenced this pull request Jul 25, 2019
segayuu added a commit that referenced this pull request Sep 7, 2019
* Revert "[BREAKING CHANGE] Replace constructor function to class declaration (#30)"

This reverts commit 34399c5.

* Run lebab

* Restore README.md before revert

* Perform class conversion not handled by lebab

* Remove unnecessary differences with master branch
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.

3 participants