Spike events system
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { nextFrame } from "helpers/timing_helpers"
|
||||
import { nextFrame } from "helpers"
|
||||
|
||||
export default class extends Controller {
|
||||
static classes = [ "play" ]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { debounce } from "helpers/timing_helpers"
|
||||
import { debounce } from "helpers"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "list" ]
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { current } from "helpers"
|
||||
|
||||
export default class extends Controller {
|
||||
static classes = [ "myComment" ]
|
||||
|
||||
connect() {
|
||||
this.#myComments.forEach(comment => comment.classList.add(this.myCommentClass))
|
||||
}
|
||||
|
||||
get #myComments() {
|
||||
return this.element.querySelectorAll(`.comment[data-creator-id='${current.user.id}']`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// On-demand JavaScript objects from "current" HTML <meta> elements. Example:
|
||||
//
|
||||
// <meta name="current-identity-id" content="123">
|
||||
// <meta name="current-identity-time-zone-name" content="Central Time (US & Canada)">
|
||||
//
|
||||
// >> current.identity
|
||||
// => { id: "123", timeZoneName: "Central Time (US & Canada)" }
|
||||
//
|
||||
// >> current.foo
|
||||
// => {}
|
||||
export const current = new Proxy({}, {
|
||||
get(_target, propertyName) {
|
||||
const result = {}
|
||||
const prefix = `current-${propertyName}-`
|
||||
for (const { name, content } of document.head.querySelectorAll(`meta[name^=${prefix}]`)) {
|
||||
const key = camelize(name.slice(prefix.length))
|
||||
result[key] = content
|
||||
}
|
||||
return result
|
||||
}
|
||||
})
|
||||
|
||||
function camelize(string) {
|
||||
return string.replace(/(?:[_-])([a-z0-9])/g, (_, char) => char.toUpperCase())
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "helpers/current_helpers"
|
||||
export * from "helpers/timing_helpers"
|
||||
Reference in New Issue
Block a user