stimulus_reflex
Advanced tools
Comparing version 0.3.7 to 1.0.0
{ | ||
"name": "stimulus_reflex", | ||
"version": "0.3.7", | ||
"version": "1.0.0", | ||
"main": "./src/index.js", | ||
@@ -13,5 +13,4 @@ "repository": { | ||
"actioncable": "^5.2.3", | ||
"cable_ready_client": "^3.0.4", | ||
"stimulus": "^1.1.1" | ||
"cable_ready": "^4.0.0" | ||
} | ||
} |
@@ -0,48 +1,7 @@ | ||
[![Lines of Code](http://img.shields.io/badge/lines_of_code-35-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/) | ||
# StimulusReflex Client | ||
JavaScript client for [StimulusReflex](https://github.com/hopsoft/stimulus_reflex) | ||
This libary is intended to work with the StimulusReflex Ruby GEM. | ||
## Installation | ||
``` | ||
yarn add stimulus_reflex | ||
``` | ||
## Usage | ||
```html | ||
<!-- app/views/pages/example.html.erb --> | ||
<html> | ||
<head></head> | ||
<body> | ||
<a href="#" data-controller="example" data-action="click->example#doStuff">Do Stuff</a> | ||
</body> | ||
</html> | ||
``` | ||
```javascript | ||
// app/javascript/controllers/example_controller.js | ||
import { StimulusReflexController } from 'stimulus_reflex'; | ||
export default class extends StimulusReflexController { | ||
doStuff(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
// trigger a server side reflex and a re-render | ||
this.stimulate('ExampleReflex#do_stuff', arg1, arg2, ...); | ||
} | ||
} | ||
``` | ||
```ruby | ||
# app/reflexes/example_reflex.rb | ||
class ExampleReflex < StimulusReflex::Reflex | ||
def do_stuff(arg1, arg2, ...) | ||
# computing... | ||
end | ||
end | ||
``` | ||
Documentation can be found at: https://github.com/hopsoft/stimulus_reflex |
@@ -1,4 +0,3 @@ | ||
import { Controller } from 'stimulus'; | ||
import ActionCable from 'actioncable'; | ||
import CableReady from 'cable_ready_client'; | ||
import CableReady from 'cable_ready'; | ||
@@ -8,7 +7,7 @@ let timeout; | ||
CableReady.App = {}; | ||
CableReady.App.cable = ActionCable.createConsumer(); | ||
CableReady.App.subscription = CableReady.App.cable.subscriptions.create( | ||
'StimulusReflex::Channel', | ||
{ | ||
CableReady.App = window.App || {}; | ||
CableReady.App.cable = CableReady.App.cable || ActionCable.createConsumer(); | ||
CableReady.App.stimulusReflexChannel = | ||
CableReady.App.stimulusReflexChannel || | ||
CableReady.App.cable.subscriptions.create('StimulusReflex::Channel', { | ||
received: data => { | ||
@@ -22,18 +21,19 @@ if (data.cableReady) { | ||
}, | ||
} | ||
); | ||
}); | ||
class StimulusReflexController extends Controller { | ||
stimulate() { | ||
clearTimeout(timeout); | ||
let args = Array.prototype.slice.call(arguments); | ||
let target = args.shift(); | ||
CableReady.App.subscription.send({ | ||
url: location.href, | ||
target: target, | ||
args: args, | ||
export default { | ||
register: controller => { | ||
Object.assign(controller, { | ||
stimulate() { | ||
clearTimeout(timeout); | ||
let args = Array.prototype.slice.call(arguments); | ||
let target = args.shift(); | ||
CableReady.App.stimulusReflexChannel.send({ | ||
url: location.href, | ||
target: target, | ||
args: args, | ||
}); | ||
}, | ||
}); | ||
} | ||
} | ||
export { StimulusReflexController }; | ||
}, | ||
}; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
34
1
1618
8
+ Addedcable_ready@^4.0.0
+ Addedcable_ready@4.5.0(transitive)
- Removedcable_ready_client@^3.0.4
- Removedstimulus@^1.1.1
- Removed@stimulus/core@1.1.1(transitive)
- Removed@stimulus/multimap@1.1.1(transitive)
- Removed@stimulus/mutation-observers@1.1.1(transitive)
- Removed@stimulus/webpack-helpers@1.1.1(transitive)
- Removedcable_ready_client@3.0.4(transitive)
- Removedstimulus@1.1.1(transitive)