MCPcopy
hub / github.com/liriliri/eruda / Snippets

Class Snippets

src/Snippets/Snippets.js:11–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import { classPrefix as c } from '../lib/util'
10
11export default class Snippets extends Tool {
12 constructor() {
13 super()
14
15 this._style = evalCss(require('./Snippets.scss'))
16
17 this.name = 'snippets'
18
19 this._snippets = []
20 }
21 init($el) {
22 super.init($el)
23
24 this._bindEvent()
25 this._addDefSnippets()
26 }
27 destroy() {
28 super.destroy()
29
30 evalCss.remove(this._style)
31 }
32 add(name, fn, desc) {
33 this._snippets.push({ name, fn, desc })
34
35 this._render()
36
37 return this
38 }
39 remove(name) {
40 remove(this._snippets, (snippet) => snippet.name === name)
41
42 this._render()
43
44 return this
45 }
46 run(name) {
47 const snippets = this._snippets
48
49 for (let i = 0, len = snippets.length; i < len; i++) {
50 if (snippets[i].name === name) this._run(i)
51 }
52
53 return this
54 }
55 clear() {
56 this._snippets = []
57 this._render()
58
59 return this
60 }
61 _bindEvent() {
62 const self = this
63
64 this._$el.on('click', '.eruda-run', function () {
65 const idx = $(this).data('idx')
66
67 self._run(idx)
68 })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…