-
-
Notifications
You must be signed in to change notification settings - Fork 72
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 append
, prepend
and replace
operations
#90
Add append
, prepend
and replace
operations
#90
Conversation
1c33cf2
to
386a0ef
Compare
append
, prepend
and replaceWith
operationappend
, prepend
and replaceWith
operations
I thought about calling it just |
95c503d
to
d0681b6
Compare
d0681b6
to
0e4e2b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work by passing a DOMString, so there isn't a requirement to construct a Node.
@hopsoft I tried that. But it always just added the HTML as actual text (that's the difference to |
The next question is whether or not there's a material difference in the following methods.
I'm mostly curious... as I think this PR is a good addition for developer happiness. |
lol... there's an echo in here |
There isn't really a difference from a user perspective other than the method names. I first wanted to implement these operations with method aliasing, but then I realized that the DOM even offers such methods. Since we always used the DOM method corresponding to the CableReady operation I thought I will do the same here. Also: If we would go the alias way, we have the problem with the events. If you alias it in the backend then the event in the frontend wouldn't match anymore and if you alias it in the frontend then both the method and the alias method events would get triggered. That's why I went with the DOM methods in this implementation in the first place. Regarding the differences: This answer here summarized it pretty good in my opinion: https://stackoverflow.com/a/16127049/5052329 Since we always just have a HTML string we need first to construct a Node in order to use But if you have the feeling that we should go the "Alias-Way" we can swap out the JS implementation. So we should just call |
Ah ok. Does that mean we could the simplify the implementation to something like this then? append: detail => {
activeElement = document.activeElement
const { element, html, focusSelector } = detail
dispatch(element, 'cable-ready:before-append', detail)
element.insertAdjacentHTML('beforeend', html)
assignFocus(focusSelector)
dispatch(element, 'cable-ready:after-append', detail)
},
// etc... |
Also, for the record.
👆🏻 This is the primary reason why I think adding these methods is a good idea. |
Exactly! If you think this approach is better I'm happy to rewrite it. |
There doesn't appear to be a material difference, so my vote is to converge on a single internal implementation by effectively delegating to the existing methods. |
How would this delegation work? I am hoping to keep things pretty obvious. |
Also rename `replaceWith` to `replace`
append
, prepend
and replaceWith
operationsappend
, prepend
and replace
operations
…operations Marcoroth/append prepend replace operations
* Global config, simplify threading, custom operations * Remove unused artifact * Remove redundant require * GitBook: [master] one page modified * Support chaining and rip deprecations out * GitBook: [master] one page modified * multiple selector element operations (#92) * `select_all` option added to all operations which support a `selector` * `cancel` option added to almost all operations, intended to be set in a `before-` event callback * substantial reorganization of `cable_ready.js` to match the order in the docs * Bump nokogiri from 1.10.10 to 1.11.1 Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.10.10 to 1.11.1. - [Release notes](https://github.com/sparklemotion/nokogiri/releases) - [Changelog](https://github.com/sparklemotion/nokogiri/blob/master/CHANGELOG.md) - [Commits](sparklemotion/nokogiri@v1.10.10...v1.11.1) Signed-off-by: dependabot[bot] <support@github.com> * Add `append`, `prepend` and `replace` operations (#90) * Disable chaining after broadcast Co-authored-by: leastbad <hello@leastbad.com> Co-authored-by: leastbad <38150464+leastbad@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marco Roth <marco.roth@intergga.ch>
Type of PR
Enhancement
Description
Adds three new operation to CableReady. After using jQuery for many years and never remembering the spelling of
insertAdjacentHTML
and the option it takes I thought it would make sense to introduce theappend
,prepend
andreplace
operations.Why should this be added
Coming from jQuery or even native JS the terms and methods
append
,prepend
andreplace
are easier to remember and could be more familiar in my opinion.Also see:
append()
andParentNode.append()
prepend()
andParentNode.prepend()
replaceWith()
andChildNode.replaceWith()
Checklist