ende 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,135 +0,0 @@
1
- 'use strict';
2
-
3
- define 'aura/extensions/widget/composable', ->
4
- stamp = extend = null
5
-
6
- advisorable = (advisor) ->
7
- # TODO merge advices in the composition chain
8
- advice_names = ['before', 'after', 'around']
9
-
10
- extract_advices = (object) ->
11
- found = []
12
- for key of object when key.indexOf('_') isnt -1
13
- [name, adviced] = key.split '_'
14
-
15
- if advice_names.indexOf(name) != -1
16
- callbacks = if object[key].length then object[key] else [object[key]]
17
-
18
- delete object[key]
19
-
20
- found.push
21
- key: key
22
- name: name
23
- adviced: adviced
24
- callbacks: callbacks
25
-
26
- found
27
-
28
- advisor.advice = (widget) ->
29
-
30
- advices = extract_advices widget
31
-
32
- for advice in advices
33
-
34
- # in order to preserve declaration order, we must reverse the callbacks order
35
- advice.callbacks.reverse() if advice.name == 'before'
36
-
37
- # Advice with all callbacks
38
- widget[advice.name] advice.adviced, callback for callback in advice.callbacks
39
-
40
- widget
41
-
42
- advisor.advisable = (factory) ->
43
- original = factory.compose
44
-
45
- stamp.mixIn factory,
46
- compose: (stamps...) ->
47
- {fixed: {methods: composition_methods}} = @composition
48
- advices = extract_advices composition_methods
49
-
50
- for stamped in stamps
51
- {fixed: {methods: stamp_methods}} = stamped
52
- advices = advices.concat extract_advices stamp_methods
53
-
54
- adviced_stamp = {}
55
- for advice in advices
56
- adviced_stamp[advice.key] ||= []
57
- adviced_stamp[advice.key] = adviced_stamp[advice.key].concat advice.callbacks
58
-
59
- # Create a ultimate stamp with all advices arrays or functions merged
60
- # TODO do not store advices definitions in the prototype chain
61
- stamps.push stamp adviced_stamp
62
-
63
- original.apply factory, stamps
64
-
65
- advice: advisor.advice
66
-
67
- advisor
68
-
69
- composerable = (compositor) ->
70
- compositor.composable = (methods, state, enclose) ->
71
- factory = (options) ->
72
-
73
- # Inherit defaults from widget
74
- options = _.defaults options, factory.composition.fixed.methods.options
75
-
76
- # Composition only will compose methods and state!
77
- instance = factory.composition options: options
78
- enclose.call instance, options
79
-
80
- # TODO check if it is needed to inherit compositions
81
- # if methods.composition
82
- # composition = methods.composition
83
- # delete methods.composition
84
- # composition = stamp.compose composition, stamp methods, state
85
- # else
86
- # composition = stamp methods, state
87
-
88
- stamp.mixIn factory,
89
- composition: stamp methods, state
90
- # Suport an extension with multiple compositions
91
- compose: -> @composition = stamp.compose @composition, arguments...
92
-
93
- extend: ->
94
- `var methods, state`
95
- {fixed} = @composition
96
- initializers = [enclose]
97
- methods = {}
98
- state = {}
99
-
100
- for definition in arguments
101
- {methods: definition_methods, state: definition_state} = definition
102
-
103
- methods = extend methods, fixed.methods, definition_methods or definition
104
- state = extend state , fixed.state , definition_state
105
-
106
- initializers.push fixed.enclose if fixed.enclose
107
- initializers.push definition.enclose if definition.enclose
108
-
109
- enclosed = (properties) ->
110
- initializers.forEach (initializer) => initializer.call @, properties
111
- @
112
-
113
- compositor.composable methods, state, enclosed or enclose
114
-
115
- compositor
116
-
117
- version: '0.1.2'
118
-
119
- initialize: (application) ->
120
- advisable = require 'ineadvisable'
121
-
122
- {core: {Widgets, util: {extend}, stamp}} = application
123
-
124
- Widgets = composerable advisorable Widgets
125
-
126
- # THINK how to at the same time respect aura ways of instantiating
127
- # widgets and preserve widget logic composability
128
- Widgets.Default = Widgets.Base
129
- delete Widgets.Default.extend
130
-
131
- Widgets.Base = Widgets.advisable Widgets.composable advisable(Widgets.Default.prototype), null, (options) ->
132
- Object.defineProperty @, 'constructor', value: Widgets.Default, enumerable: false, configurable: false, writable: false
133
- Widgets.Default.call Widgets.advice(@), options
134
-
135
-