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

Add update() method #1186

Merged
merged 1 commit into from Jan 18, 2019
Merged

Add update() method #1186

merged 1 commit into from Jan 18, 2019

Conversation

limonte
Copy link
Member

@limonte limonte commented Jul 27, 2018

I believe this is much better than #1152

Renderers were introduced recently, there are currently 2 renderers: https://github.com/sweetalert2/sweetalert2/tree/master/src/utils/dom/renderers

Renderers allow to re-render particular parts of a popup without re-initialization:

peek 2018-07-27 10-18

I'm quite happy with this implementation. What do you think @zenflow?

@limonte limonte requested a review from zenflow July 27, 2018 07:42
@coveralls
Copy link

coveralls commented Jul 27, 2018

Pull Request Test Coverage Report for Build 4519

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 20 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 90.489%

Files with Coverage Reduction New Missed Lines %
dist/sweetalert2.js 20 90.49%
Totals Coverage Status
Change from base Build 4517: -0.01%
Covered Lines: 1136
Relevant Lines: 1206

💛 - Coveralls

@limonte limonte changed the title Add update() method [WIP] Add update() method Jul 27, 2018
@limonte
Copy link
Member Author

limonte commented Jul 27, 2018

@zenflow after the green light from, I'll cover the new functionality with tests to keep code coverage on a 90+ level 🥇

@limonte limonte force-pushed the feat/update-with-renderers branch 2 times, most recently from 7146709 to a0046cb Compare July 28, 2018 12:01
Copy link
Member

@zenflow zenflow left a comment

Choose a reason for hiding this comment

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

@limonte sorry for the delay in getting to this. I've given this review a lot of thought, and I'm generally pretty happy with the change. I'm also really happy about the renderers. I agree it's a great step forward in the organization of the codebase. The next logical step might be to colocate the bits of pre-rendering (construction or setup) logic with their respective renderers.

I linked this against sweetalert2-react-content to test out the API from the point-of-view of an extension. I had to do some reorganization (and fix a prexisting bug sweetalert2/sweetalert2-react-content#58) but it was easy to get the enhancer to work with this feature. You can check out https://github.com/sweetalert2/sweetalert2-react-content/tree/feature/integrate-update-method .. note that the instance properties prefixed __ need to be fixed to be truly private.

Some issues:

The first two are related: Firstly, it would nice if each extension did not need to manage it's own params object; i.e. storing it and updating it. Currently, if you (as an extension) want to know the complete set of effective params from inside the update method (not just the subset that are being updated) you need to track that yourself. It's not that much extra code or complexity, but it might not be necessary, i.e. we might be able to handle it in the core. Secondly, the instance's params property (i.e. the "outer" params, which were defined with the user's call to Swal) should probably be updated when the update method is called, as this would likely be expected. As far as I can figure, the only way to do this properly, while still giving subclasses the ability to control the params given to the superclass, would be to have a "protected" method that you can extend that does the actual work, and the update method just updates the instances public params property and calls the protected method. This update method could also solve the first issue by passing the complete set of [outer] params to the protected method.

The other issue is one that is already existing, that I contributed to, that this PR is also contributing to: the exposing of isValidParameter, isDeprecatedParameter & isUpdatableParameter as public methods.. what use case do they serve? and are they expected to be implemented in relevant extensions (that add or remove params)? That's a little bit of overhead, and is likely to be forgotten (even if documented), so I would not necessarily trust them. In most cases, I think it is enough for the public API to log warnings (or throw errors) when you try to do something invalid, so what do you think about deprecating these methods in the public API and removing them in the next major? For now I'm cool with either adding this new isUpdatableParameter method or not, either way.

@limonte limonte force-pushed the master branch 22 times, most recently from 9513a65 to c3c882f Compare September 5, 2018 21:52
@limonte limonte force-pushed the master branch 2 times, most recently from e5fdbb7 to 3c3fbbb Compare September 6, 2018 14:15
@limonte limonte force-pushed the master branch 3 times, most recently from d28e146 to 3b53594 Compare October 7, 2018 12:36
@limonte limonte force-pushed the feat/update-with-renderers branch 2 times, most recently from f845ca3 to b4d009f Compare January 18, 2019 07:31
@limonte limonte closed this Jan 18, 2019
@limonte limonte deleted the feat/update-with-renderers branch January 18, 2019 11:43
@limonte limonte restored the feat/update-with-renderers branch January 18, 2019 11:44
@limonte limonte reopened this Jan 18, 2019
@limonte
Copy link
Member Author

limonte commented Jan 18, 2019

oops, wrong button

@limonte limonte closed this Jan 18, 2019
@limonte limonte reopened this Jan 18, 2019
@limonte limonte changed the title [WIP] Add update() method Add update() method Jan 18, 2019
@limonte
Copy link
Member Author

limonte commented Jan 18, 2019

I'll just ship this feature as it is :shipit:

@limonte limonte merged commit 56a137d into master Jan 18, 2019
@limonte limonte deleted the feat/update-with-renderers branch January 18, 2019 13:42
limonte added a commit that referenced this pull request Jan 18, 2019
limonte added a commit that referenced this pull request Jan 18, 2019
@zenflow
Copy link
Member

zenflow commented Jan 18, 2019

@limonte Disappointed that we could not work on this so that it remains easy to extend Swal..

Also, in my comment I indicated a problem/bug:

the instance's params property (i.e. the "outer" params, which were defined with the user's call to Swal) should probably be updated when the update method is called, as this would likely be expected

@gverni
Copy link
Contributor

gverni commented Jan 18, 2019

Also, in my comment I indicated a problem/bug:

Happy to work on that @limonte @zenflow if you think it's worth it. My only question (to better understand how it can be used) is what would be the use case for that @zenflow? Let's say that a developer change the swal type: in which condition does he/she wants to check again the value of that property? Is it to implement a kind of state machine on a running swal? And does that affect the mixin as well (in case there is one)?

limonte pushed a commit that referenced this pull request Jan 19, 2019
# [8.0.0](v7.33.1...v8.0.0) (2019-01-19)

* BREAKING CHANGE: remove getButtonsWrapper() ([c93b5e3](c93b5e3))
* BREAKING CHANGE: close() as instance method (#1379) ([2519c17](2519c17)), closes [#1379](#1379)
* BREAKING CHANGE: replace deprecated `jsnext:main` with `module` in package.json (#1378) ([1785905](1785905)), closes [#1378](#1378)
* BREAKING CHANGE: drop Bower support (#1377) ([cb4ef28](cb4ef28)), closes [#1377](#1377)
* BREAKING CHANGE: remove withNoNewKeyword enhancer (#1372) ([f581352](f581352)), closes [#1372](#1372)
* BREAKING CHANGE: remove swal.noop() ([40d6fbb](40d6fbb))
* BREAKING CHANGE: rename $swal2-validationerror -> $swal2-validation-message (#1370) ([9d1b13b](9d1b13b)), closes [#1370](#1370)
* BREAKING CHANGE: inputValidator and preConfirm should always resolve (#1383) ([fc70cf9](fc70cf9)), closes [#1383](#1383)
* BREAKING CHANGE: remove setDefault and resetDefaults (#1365) ([97c1d7c](97c1d7c)), closes [#1365](#1365)
* BREAKING CHANGE: remove extraParams (#1363) ([5125491](5125491)), closes [#1363](#1363)
* BREAKING CHANGE: remove showValidationError and resetValidationError (#1367) ([50a1eff](50a1eff)), closes [#1367](#1367)
* BREAKING CHANGE: remove useRejections and expectRejections (#1362) ([f050caf](f050caf)), closes [#1362](#1362)
* BREAKING CHANGE: dismissReason: overlay -> backdrop (#1360) ([d05bf33](d05bf33)), closes [#1360](#1360)
* BREAKING CHANGE: drop Android 4.4 support (#1359) ([c0eddf3](c0eddf3)), closes [#1359](#1359)

### Features

* **api:** add update() method ([#1186](#1186)) ([348e8b7](348e8b7))

### BREAKING CHANGES

* close() as instance method (#1379)
* drop Android 4.4 support (#1359)
* replace deprecated `jsnext:main` with `module` in package.json (#1378)
* drop Bower support (#1377)
* remove withNoNewKeyword enhancer (#1372)
* remove swal.noop()
* rename $swal2-validationerror -> $swal2-validation-message (#1370)
* inputValidator and preConfirm should always resolve (#1383)
* remove setDefault and resetDefaults (#1365)
* remove extraParams (#1363)
* remove showValidationError and resetValidationError (#1367)
* remove useRejections and expectRejections (#1362)
* dismissReason: overlay -> backdrop (#1360)
* remove getButtonsWrapper()
@limonte
Copy link
Member Author

limonte commented Jan 19, 2019

@zenflow I personally do not see any of those as critical issues, if they are we will fix them and ship as patch releases because they will not affect public APIs.

Please elaborate a bit more on:

  • which are potential use-cases which won't work as expected
  • what is actual behavior
  • what is expected behavior

Proper issue-reports (with some code, actual and expected behaviors) and/or PRs are very welcome.

@zenflow
Copy link
Member

zenflow commented Jan 19, 2019

Opened #1386 ...

The other recommendations were critical to Swal being easy to extend.. something I worked very hard on.

Those recommendations included changes to the "protected" API (i.e. extensions depend on it; changes to it can break code outside of this repo) as well as the public API (e.g. removing isValidParameter, isDeprecatedParameter & isUpdatableParameter from the public API).

I'm not sure why you are so hasty to make the major release, when there are still many things in the API that could have been fixed or improved, e.g. #1373, but now we are stuck with for another major version, unless you are fine with making major breaking changes in patch releases.

@limonte
Copy link
Member Author

limonte commented Jan 19, 2019

I'm not sure why you are so hasty

The process of releasing a new major took 11 days: aa657e5...v8.0.0 I wouldn't call it hasty. Everybody noticed PRs with "BREAKING CHANGE" in their titles and was able to participate.

We all have limited time, I personally don't need anything from #1373 or #1386 for my projects, that is why I didn't work on them. At the same time, new major contains some really important changes (e.g. ES modules support) which people need and my responsibility as a mantainer fo this project is to ship that as soon as possible.

#1373 has appeared after I started the new major process and it lacks use-cases with code examples, actual and expected behaviors, that's why I didn't work on it. I will ask for clarifications there, but it's a bit impolite to drop issues without following issue templates and expect them to be done.

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.

None yet

4 participants