native-document 1.0.237 → 1.0.240

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.237",
3
+ "version": "1.0.240",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",
@@ -1,8 +1,8 @@
1
1
  import {classPropertyAccumulator, cssPropertyAccumulator} from '../core/utils/property-accumulator';
2
2
  import {Observable} from '../core/data/Observable';
3
- import {ShowIf} from '../core/elements/control/show-if';
3
+ import {ShowIf} from '../core/elements';
4
4
  import {NDElement} from '../core/wrappers/NDElement';
5
- import {EVENTS} from '../core/utils/events';
5
+ import {EVENTS, EVENTS_WITH_PREVENT, EVENTS_WITH_STOP} from '../core/utils/events';
6
6
 
7
7
  /**
8
8
  *
@@ -33,12 +33,9 @@ Object.defineProperty( BaseComponent.prototype, 'nd', {
33
33
  });
34
34
 
35
35
 
36
- EVENTS.forEach((eventSourceName) => {
37
- const eventName = eventSourceName.toLowerCase();
38
- const fnName = 'on'+eventSourceName;
39
-
40
- BaseComponent.prototype[fnName] = function(callback = null, options = null) {
36
+ const $eventWrapper = (eventName, fnName) => {
41
37
 
38
+ return function(callback = null, options = null) {
42
39
  const callbackWrapper = (...args) => {
43
40
  callback.apply(this, args);
44
41
  this.emit ? this.emit(eventName, ...args) : null;
@@ -53,7 +50,25 @@ EVENTS.forEach((eventSourceName) => {
53
50
  });
54
51
  return this;
55
52
  };
53
+ };
54
+
55
+ EVENTS.forEach((eventSourceName) => {
56
+ const eventName = eventSourceName.toLowerCase();
57
+ const fnName = 'on'+eventSourceName;
56
58
 
59
+ BaseComponent.prototype[fnName] = $eventWrapper(eventName, fnName);
60
+ });
61
+
62
+ EVENTS_WITH_STOP.forEach((eventSourceName) => {
63
+ const eventName = eventSourceName.toLowerCase();
64
+ const fnName = 'onStop'+eventSourceName;
65
+ BaseComponent.prototype[fnName] = $eventWrapper(eventName, fnName);
66
+ });
67
+
68
+ EVENTS_WITH_PREVENT.forEach((eventSourceName) => {
69
+ const eventName = eventSourceName.toLowerCase();
70
+ const fnName = 'onPrevent'+eventSourceName;
71
+ BaseComponent.prototype[fnName] = $eventWrapper(eventName, fnName);
57
72
  });
58
73
 
59
74
  /**
@@ -166,8 +181,14 @@ BaseComponent.prototype.toNdElement = function() {
166
181
  const nd = this.$element.nd;
167
182
  nd.ghostDom(this.$attachements);
168
183
  this.$attachements = null;
184
+ if(this.$applyEventsToElement) {
185
+ this.$applyEventsToElement(nd);
186
+ }
169
187
  return nd;
170
188
  }
189
+ if(this.$applyEventsToElement) {
190
+ this.$applyEventsToElement(this.$element);
191
+ }
171
192
 
172
193
  return this.$element;
173
194
  };
@@ -54,6 +54,16 @@ HasEventEmitter.prototype.hasListeners = function(eventName) {
54
54
  return !!this.__$events.get(eventName);
55
55
  };
56
56
 
57
+ HasEventEmitter.prototype.$applyEventsToElement = function(element) {
58
+ if(!this.__$events) {
59
+ return;
60
+ }
61
+ for(const eventName in this.__$events) {
62
+ const event = this.__$events.get(eventName);
63
+ console.log(event, eventName);
64
+ }
65
+ };
66
+
57
67
  /**
58
68
  * Fires all registered callbacks for the given event name, awaiting each one in sequence.
59
69
  * Returns the result of the last callback. Alias: .emit()
@@ -90,10 +90,13 @@ export function SingletonView($viewCreator) {
90
90
  export function useSingleton(fn) {
91
91
  let $cache = null;
92
92
 
93
- return function(...args) {
93
+ const callback = function(...args) {
94
94
  if(!$cache) {
95
95
  $cache = new SingletonView(fn);
96
+ callback.render = $cache.render.bind($cache);
96
97
  }
97
98
  return $cache.render(args);
98
99
  };
100
+
101
+ return callback;
99
102
  }