New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

stimulus_reflex

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stimulus_reflex - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

stimulus_reflex_controller.js

5

package.json
{
"name": "stimulus_reflex",
"version": "1.1.1",
"version": "2.0.0",
"main": "./stimulus_reflex.js",

@@ -16,3 +16,4 @@ "scripts": {

"actioncable": ">= 5.2",
"cable_ready": ">= 4.0.3"
"cable_ready": ">= 4.0.3",
"stimulus": ">= 1.1.1"
},

@@ -19,0 +20,0 @@ "devDependencies": {

62

stimulus_reflex.js
import ActionCable from 'actioncable';
import CableReady from 'cable_ready';
import StimulusReflexController from './stimulus_reflex_controller';

@@ -63,18 +64,47 @@ const app = window.App || {};

export default {
//
// Registers a Stimulus controller and extends it with StimulusReflex behavior
// The room can be specified via a data attribute on the Stimulus controller element i.e. data-room="12345"
//
// controller - the Stimulus controller
// options - optional configuration
// * renderDelay - amount of time to delay before mutating the DOM (adds latency but reduces jitter)
//
register: (controller, options = {}) => {
const channel = 'StimulusReflex::Channel';
const room = controller.element.dataset.room || '';
controller.StimulusReflex = { ...options, channel, room };
createSubscription(controller);
extend(controller);
},
// Sets up implicit declarative reflex behavior
const setup = () => {
document.querySelectorAll('[data-reflex]').forEach(el => {
if (String(el.dataset.controller).indexOf('stimulus-reflex') >= 0) return;
const controllers = el.dataset.controller ? el.dataset.controller.split(' ') : [];
const actions = el.dataset.action ? el.dataset.action.split(' ') : [];
controllers.push('stimulus-reflex');
el.setAttribute('data-controller', controllers.join(' '));
el.dataset.reflex.split(' ').forEach(reflex => {
actions.push(`${reflex.split('->')[0]}->stimulus-reflex#perform`);
});
el.setAttribute('data-action', actions.join(' '));
});
};
// Initializes StimulusReflex by registering the default Stimulus controller
// with the passed Stimulus application
const initialize = application => {
application.register('stimulus-reflex', StimulusReflexController);
};
// Registers a Stimulus controller and extends it with StimulusReflex behavior
// The room can be specified via a data attribute on the Stimulus controller element i.e. data-room="12345"
//
// controller - the Stimulus controller
// options - optional configuration
// * renderDelay - amount of time to delay before mutating the DOM (adds latency but reduces jitter)
//
const register = (controller, options = {}) => {
const channel = 'StimulusReflex::Channel';
const room = controller.element.dataset.room || '';
controller.StimulusReflex = { ...options, channel, room };
createSubscription(controller);
extend(controller);
};
StimulusReflexController.register = register;
if (!document.stimulusReflexInitialized) {
document.stimulusReflexInitialized = true;
window.addEventListener('load', setup);
document.addEventListener('turbolinks:load', setup);
document.addEventListener('cable-ready:after-morph', setup);
}
export default { initialize, register };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc