stimulus_reflex
Advanced tools
Comparing version 3.5.0-rc3 to 3.5.0-rc4
@@ -948,3 +948,3 @@ import { Controller } from "@hotwired/stimulus"; | ||
var version = "3.5.0-rc3"; | ||
var version = "3.5.0-rc4"; | ||
@@ -1264,3 +1264,3 @@ var description = "Build reactive applications with the Rails tooling you already know and love."; | ||
})); | ||
return controller || controllers[0]; | ||
return controller; | ||
}; | ||
@@ -1286,3 +1286,4 @@ | ||
const parentControllerElement = element.closest(`[data-controller~=${controllerName}]`); | ||
if (!parentControllerElement) { | ||
const elementPreviouslyHadStimulusReflexController = element === parentControllerElement && controllerName === "stimulus-reflex"; | ||
if (!parentControllerElement || elementPreviouslyHadStimulusReflexController) { | ||
controllers.push(controllerName); | ||
@@ -1446,2 +1447,3 @@ } | ||
__proto__: null, | ||
StimulusReflexController: StimulusReflexController, | ||
initialize: initialize, | ||
@@ -1474,2 +1476,2 @@ reflexes: reflexes, | ||
export { global as default, initialize, reflexes, register, scanForReflexes, scanForReflexesOnElement, useReflex }; | ||
export { StimulusReflexController, global as default, initialize, reflexes, register, scanForReflexes, scanForReflexesOnElement, useReflex }; |
@@ -872,3 +872,3 @@ (function(global, factory) { | ||
var name = "stimulus_reflex"; | ||
var version = "3.5.0-rc3"; | ||
var version = "3.5.0-rc4"; | ||
var description = "Build reactive applications with the Rails tooling you already know and love."; | ||
@@ -1156,3 +1156,3 @@ var keywords = [ "ruby", "rails", "websockets", "actioncable", "turbolinks", "reactive", "cable", "ujs", "ssr", "stimulus", "reflex", "stimulus_reflex", "dom", "morphdom" ]; | ||
})); | ||
return controller || controllers[0]; | ||
return controller; | ||
}; | ||
@@ -1176,3 +1176,4 @@ const scanForReflexes = debounce((() => { | ||
const parentControllerElement = element.closest(`[data-controller~=${controllerName}]`); | ||
if (!parentControllerElement) { | ||
const elementPreviouslyHadStimulusReflexController = element === parentControllerElement && controllerName === "stimulus-reflex"; | ||
if (!parentControllerElement || elementPreviouslyHadStimulusReflexController) { | ||
controllers.push(controllerName); | ||
@@ -1324,2 +1325,3 @@ } | ||
__proto__: null, | ||
StimulusReflexController: StimulusReflexController, | ||
initialize: initialize, | ||
@@ -1349,2 +1351,3 @@ reflexes: reflexes, | ||
window.StimulusReflex = global; | ||
exports.StimulusReflexController = StimulusReflexController; | ||
exports.default = global; | ||
@@ -1351,0 +1354,0 @@ exports.initialize = initialize; |
@@ -46,5 +46,5 @@ import App from './app' | ||
return controller || controllers[0] | ||
return controller | ||
} | ||
export { allReflexControllers, findControllerByReflexName } | ||
export { localReflexControllers, allReflexControllers, findControllerByReflexName } |
@@ -45,3 +45,5 @@ import Schema from './schema' | ||
if (!parentControllerElement) { | ||
const elementPreviouslyHadStimulusReflexController = (element === parentControllerElement && controllerName === 'stimulus-reflex') | ||
if (!parentControllerElement || elementPreviouslyHadStimulusReflexController) { | ||
controllers.push(controllerName) | ||
@@ -48,0 +50,0 @@ } |
@@ -35,3 +35,3 @@ import { Controller } from '@hotwired/stimulus' | ||
// | ||
class StimulusReflexController extends Controller { | ||
export class StimulusReflexController extends Controller { | ||
constructor (...args) { | ||
@@ -38,0 +38,0 @@ super(...args) |
@@ -34,2 +34,9 @@ import { assert } from '@open-wc/testing' | ||
it('returns expected attribute value for array with duplicate values', () => { | ||
assert.equal( | ||
attributeValue(['one', 'two', 'three', 'three', 'two', 'one']), | ||
'one two three' | ||
) | ||
}) | ||
it('returns expected attribute value for array with mixed and duplicate values', () => { | ||
@@ -36,0 +43,0 @@ assert.equal( |
@@ -8,9 +8,9 @@ import { assert } from '@open-wc/testing' | ||
it('returns undefined if empty controllers array is passed', () => { | ||
assert.equal( | ||
findControllerByReflexName('click->TestReflex#create', []), | ||
undefined | ||
assert.isUndefined( | ||
findControllerByReflexName('click->TestReflex#create', []) | ||
) | ||
assert.isUndefined(findControllerByReflexName('click->Test#create', [])) | ||
}) | ||
it('returns first controller if no matching controller is found', () => { | ||
it('returns no controller if no matching controller is found', () => { | ||
const controller = { identifier: 'test' } | ||
@@ -23,6 +23,8 @@ const controllers = [ | ||
assert.equal( | ||
findControllerByReflexName('click->NoReflex#create', controllers), | ||
controllers[0] | ||
assert.isUndefined( | ||
findControllerByReflexName('click->NoReflex#create', controllers) | ||
) | ||
assert.isUndefined( | ||
findControllerByReflexName('click->No#create', controllers) | ||
) | ||
}) | ||
@@ -42,2 +44,7 @@ | ||
) | ||
assert.equal( | ||
findControllerByReflexName('click->Test#create', controllers), | ||
controller | ||
) | ||
}) | ||
@@ -60,2 +67,10 @@ | ||
) | ||
assert.equal( | ||
findControllerByReflexName( | ||
'click->Some::Deep::Module::Test#create', | ||
controllers | ||
), | ||
controller | ||
) | ||
}) | ||
@@ -75,3 +90,8 @@ | ||
) | ||
assert.equal( | ||
findControllerByReflexName('click->SomeThing#create', controllers), | ||
controller | ||
) | ||
}) | ||
}) |
@@ -12,5 +12,3 @@ import { html, fixture, assert } from '@open-wc/testing' | ||
function registeredControllers () { | ||
return Array.from(App.app.router.modulesByIdentifier.keys()) | ||
} | ||
import { unloadAllControllers, registeredControllers } from './test_helpers' | ||
@@ -23,3 +21,3 @@ describe('scanForReflexesOnElement', () => { | ||
afterEach(() => { | ||
App.app.unload(registeredControllers()) | ||
unloadAllControllers() | ||
}) | ||
@@ -327,2 +325,42 @@ | ||
}) | ||
it('should remove stimulus-reflex controller when other controller is a matching StimulusReflex-enabled controller', async () => { | ||
App.app.register('example', ExampleController) | ||
const controllerElement = await fixture(html` | ||
<div | ||
data-controller="example stimulus-reflex" | ||
data-reflex="click->Example#else" | ||
></div> | ||
`) | ||
scanForReflexesOnElement(controllerElement) | ||
assert.equal(controllerElement.dataset.controller, 'example') | ||
assert.equal(controllerElement.dataset.reflex, 'click->Example#else') | ||
assert.equal(controllerElement.dataset.action, 'click->example#__perform') | ||
}) | ||
it('should not remove stimulus-reflex controller when other controller is a non-matching StimulusReflex-enabled controller', async () => { | ||
App.app.register('example', ExampleController) | ||
const controllerElement = await fixture(html` | ||
<div | ||
data-controller="example stimulus-reflex" | ||
data-reflex="click->Something#else" | ||
></div> | ||
`) | ||
scanForReflexesOnElement(controllerElement) | ||
assert.equal( | ||
controllerElement.dataset.controller, | ||
'example stimulus-reflex' | ||
) | ||
assert.equal(controllerElement.dataset.reflex, 'click->Something#else') | ||
assert.equal( | ||
controllerElement.dataset.action, | ||
'click->stimulus-reflex#__perform' | ||
) | ||
}) | ||
}) |
{ | ||
"name": "stimulus_reflex", | ||
"version": "3.5.0-rc3", | ||
"version": "3.5.0-rc4", | ||
"description": "Build reactive applications with the Rails tooling you already know and love.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
263852
51
7082