-
-
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
before -> operate -> after #110
Conversation
Late thought: think of |
I like where this is going, and want to float an idea to see if we can push the concept further. What if we introduce a promise to facilitate the const operate = (element, operation, callee, callback) => {
before(element, callee, operation)
if (!operation.cancel) {
if (operation.delay) {
new Promise((resolve, reject) => {
setTimeout(() => resolve(callback()), operation.delay)
}).then(() => after(element, callee, operation))
} else {
callback()
after(element, callee, operation)
}
}
} The operations could then further simplify to something along these lines. append: (operation, callee) => {
processElements(operation, element => {
operate(element, operation, callee, () => {
const { html, focusSelector } = operation
element.insertAdjacentHTML('beforeend', html || '')
assignFocus(focusSelector)
})
})
} I also wonder if passing append: (operation) => {
processElements(operation, element => {
operate('append', element, operation, () => { ... |
Hey, my head hasn't been in this for a few months but:
|
That's a very good reason to keep I think we may be able to avoid passing |
I'm excited to make this even cleaner. Passing in the |
Just to think for a moment about your proposal to move I'm also in the process of moving That would mean that we'd add events to operations that really don't make sense to have events, most specifically |
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.
I tried a few things that eliminated the need to pass callee
around but haven't been satisfied with any of them. I think we can merge and perhaps continue exploring ways to make this cleaner in the future.
Building on #109, this PR aims to standardize the way operations are defined by introducing a light DSL that can be used in a consistent pattern.
Previously, we call dispatch directly to emit before and after events, which clutters the code, is non-DRY and leaves open the possibility of typos. Instead, I would like to switch to
before
andafter
functions which are intended to immediately preceed and immediately follow theoperate
closure.What is the
operate
closure!?I noticed that a number of features being added (or proposed) was adding code to every one of the operations. Again, this is a smell. Instead, I created
operate
to function as a pipeline for modifying all of the operations. This allowed me to move out thecancel: true
check from each operation, and introduce a new option,delay
, which allows developers to stagger execution of individual operations. This can be useful for UI/UX reasons, as well as giving 3rd-party components a few ms to "catch up" if necessary.operate
could someday be pluggable, as well, although I don't attempt it in this PR.The cool thing about the
processElements
andoperate
functions is that developers building custom events can import them and use them, or not, as they wish. I already document usingprocessElements
in today's documentation... this just picks up where it left off.