Skip to content

Commit 975ef95

Browse files
committed
Initial commit
0 parents  commit 975ef95

File tree

9 files changed

+2752
-0
lines changed

9 files changed

+2752
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Prettier-Standard
2+
on: [pull_request, push]
3+
jobs:
4+
prettier:
5+
name: Prettier-Standard Check Action
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@master
9+
- name: Setup Node
10+
uses: actions/setup-node@v1
11+
with:
12+
version: '12.x'
13+
- run: yarn
14+
- run: yarn lint

.github/workflows/publish.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Publish NPM Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 12
15+
registry-url: https://registry.npmjs.org/
16+
scope: '@cable_ready'
17+
18+
- run: yarn install
19+
- run: git config --global user.email "[email protected]" && git config --global user.name "$GITHUB_ACTOR"
20+
- run: yarn publish
21+
env:
22+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.vscode
2+
/.bundle/
3+
/.yardoc
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
node_modules/
11+
.vscode
12+
/packages/**/dist/
13+
lerna-debug.log
14+
yarn-error.log
15+
*~
16+
.byebug_history

.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.gemspec
2+
*.rb
3+
.gitbook
4+
.gitbook.yml
5+
.github
6+
.tool-versions
7+
Gemfile*
8+
Rakefile
9+
assets
10+
bin
11+
docs
12+
lib
13+
pkg
14+
tags

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 Nathan Hopkins
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Package `@cable_ready/invoke_operations`
2+
3+
A collection of invoke operations meant to be used with [`cable_ready`](https://github.com/cableready/cable_ready).
4+
5+
6+
### Installation
7+
8+
Install `@cable_ready/invoke_operations` in your application:
9+
10+
```bash
11+
yarn add @cable_ready/invoke_operations
12+
13+
# or
14+
15+
npm install --save @cable_ready/invoke_operations
16+
```
17+
18+
### Usage
19+
20+
Add the invoke operations to CableReady:
21+
22+
```javascript
23+
// app/javascript/packs/application.js
24+
25+
import CableReady from 'cable_ready'
26+
import InvokeOperations from '@cable_ready/invoke_operations'
27+
28+
CableReady.addOperations(InvokeOperations)
29+
```
30+
31+
And configure CableReady on the Ruby side to include the new operation:
32+
33+
```ruby
34+
# config/initializers/cable_ready.rb
35+
36+
CableReady.configure do |config|
37+
config.add_operation_name :invoke_method
38+
end
39+
```

index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Utils } from 'cable_ready'
2+
3+
const { before, operate, after } = Utils
4+
5+
export default {
6+
invokeMethod: operation => {
7+
processElements(operation, element => {
8+
before(element, operation)
9+
operate(operation, () => {
10+
let firstObjectInChain
11+
const { element, receiver, method, args } = operation
12+
const chain = method.split('.')
13+
14+
switch (receiver) {
15+
case 'window':
16+
firstObjectInChain = window
17+
break
18+
case 'document':
19+
firstObjectInChain = document
20+
break
21+
default:
22+
firstObjectInChain = element
23+
}
24+
let lastObjectInChain = firstObjectInChain
25+
const foundMethod = chain.reduce((lastTerm, nextTerm) => {
26+
lastObjectInChain = lastTerm
27+
return lastTerm[nextTerm] || {}
28+
}, firstObjectInChain)
29+
30+
if (foundMethod instanceof Function) {
31+
foundMethod.apply(lastObjectInChain, args || [])
32+
} else {
33+
console.warn(
34+
`CableReady invoke_method operation failed due to missing '${method}' method for:`,
35+
firstObjectInChain
36+
)
37+
}
38+
})
39+
after(element, operation)
40+
})
41+
}
42+
}

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@cable_ready/invoke_operations",
3+
"version": "5.0.0-pre9",
4+
"description": "CableReady Invoke Operations",
5+
"repository": "https://github.com/cableready/invoke_operations",
6+
"homepage": "https://cableready.stimulusreflex.com/",
7+
"bugs": "https://github.com/cableready/invoke_operations/issues",
8+
"license": "MIT",
9+
"author": "Nathan Hopkins <[email protected]>",
10+
"source": "./index.js",
11+
"main": "./index.js",
12+
"scripts": {
13+
"lint": "yarn run prettier-standard:check",
14+
"format": "yarn run prettier-standard:format",
15+
"prettier-standard:check": "yarn run prettier-standard --check *.js **/*.js",
16+
"prettier-standard:format": "yarn run prettier-standard *.js **/*.js"
17+
},
18+
"peerDependencies": {
19+
"cable_ready": ">= 5.0.0-pre9"
20+
},
21+
"devDependencies": {
22+
"prettier-standard": "^16.4.1"
23+
},
24+
"publishConfig": {
25+
"access": "public"
26+
}
27+
}

0 commit comments

Comments
 (0)