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

Introduce OperationStore to add operations on-the-fly #124

Merged
merged 4 commits into from
May 13, 2021

Conversation

marcoroth
Copy link
Member

Type of PR

Feature

Description

This PR introduces a OperationStore to add operations on-the-fly.

This also removes the playSound operation. The operation has been extracted to: https://github.com/cableready/audio_operations

With that a developer can add custom operations from packages to their app.

// app/javascript/packs/application.js

import CableReady from 'cable_ready'
import AudioOperations from '@cable_ready/audio_operations'

CableReady.addOperations(AudioOperations)

Deprecate CableReady.DOMOperations

As CableReady is more than just "DOM operations" we should also change the name. This is still supported but shows a deprecation warning:

CableReady.DOMOperations.jazzHands = (operation, name) => {
 console.log('Jazz hands!', operation)
}

Instead you can now use this:

CableReady.operations.jazzHands = (operation, name) => {
 console.log('Jazz hands!', operation)
}

As a side effect it now also allows more ways of defining custom operations:

CableReady.addOperations({
 jazzHands: (operation, name) => {
   console.log('Jazz hands!', operation)
 },
 jazz: (operation, name) => {
   console.log('Jazz!', operation)
 }
})

CableReady.addOperation('jazzHands', (operation, name) => {
 console.log('Jazz hands!', operation)
})

Why should this be added

Developers can build npm packages with pre-build CableReady operations and just add them with a simple function call to CableReady.

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing
  • This is not a documentation update

@leastbad leastbad added enhancement javascript Pull requests that update Javascript code proposal labels May 11, 2021
Copy link
Contributor

@leastbad leastbad left a comment

Choose a reason for hiding this comment

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

This is a masterclass-level refactoring job. Bravo.

@julianrubisch
Copy link
Contributor

Would it make sense to implement OperationStore in JS class notation (for better readability)?

Copy link
Contributor

@hopsoft hopsoft left a comment

Choose a reason for hiding this comment

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

Very nice! Great job.

javascript/stream_from_element.js Show resolved Hide resolved
@hopsoft
Copy link
Contributor

hopsoft commented May 13, 2021

Would it make sense to implement OperationStore in JS class notation (for better readability)?

I'm ok to punt on this unless y'all feel we should do it now vs later.

and when it's not our `stream-from` element
@leastbad leastbad merged commit 2efa3b8 into stimulusreflex:master May 13, 2021
@marcoroth marcoroth deleted the add-operations branch May 13, 2021 22:38
@marcoroth marcoroth restored the add-operations branch May 13, 2021 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement javascript Pull requests that update Javascript code proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants