summaryrefslogtreecommitdiffstats
path: root/src/utils/methods.js
blob: 4973d13997ff88cc21c5f49078fe2a053f355e31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const methods = {}
const constructors = {}
const names = []

export function registerMethods ( name, m ) {

  if ( Array.isArray( name ) ) {

    for ( let _name of name ) {

      registerMethods( _name, m )

    }
    return

  }

  if ( typeof name === 'object' ) {

    for ( let [ _name, _m ] of Object.entries( name ) ) {

      registerMethods( _name, _m )

    }
    return

  }

  addMethodNames( Object.keys( m ) )
  methods[name] = Object.assign( methods[name] || {}, m )

}

export function getMethodsFor ( name ) {

  return methods[name] || {}

}

export function getMethodNames () {

  return [ ...new Set( names ) ]

}

export function addMethodNames ( _names ) {

  names.push( ..._names )

}

export function registerConstructor ( name, setup ) {

  constructors[name] = setup

}

export function getConstructor ( name ) {

  return constructors[name] ? { setup: constructors[name], name } : {}

}