alchemymvc 1.3.8 → 1.3.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.
@@ -28,6 +28,17 @@ var LoopConduit = Function.inherits('Alchemy.Conduit', function Loopback(parent_
28
28
  }
29
29
  });
30
30
 
31
+ /**
32
+ * Refer to the parent conduit for the sessionData property
33
+ *
34
+ * @author Jelle De Loecker <jelle@elevenways.be>
35
+ * @since 1.3.10
36
+ * @version 1.3.10
37
+ */
38
+ LoopConduit.setProperty(function sessionData() {
39
+ return this.parent.sessionData;
40
+ });
41
+
31
42
  /**
32
43
  * Create a new loopback
33
44
  *
@@ -244,4 +255,19 @@ LoopConduit.setMethod(function error(status, message, print_error) {
244
255
  } else {
245
256
  this.end(message);
246
257
  }
258
+ });
259
+
260
+ /**
261
+ * Create a session
262
+ *
263
+ * @author Jelle De Loecker <jelle@elevenways.be>
264
+ * @since 1.3.10
265
+ * @version 1.3.10
266
+ *
267
+ * @param {Boolean} create Create a session if none exist
268
+ *
269
+ * @return {UserSession}
270
+ */
271
+ LoopConduit.setMethod(function getSession(allow_create = true) {
272
+ return this.parent.getSession(allow_create);
247
273
  });
@@ -6,7 +6,7 @@ var iostream = alchemy.use('socket.io-stream'),
6
6
  *
7
7
  * @author Jelle De Loecker <jelle@develry.be>
8
8
  * @since 0.2.0
9
- * @version 1.1.3
9
+ * @version 1.3.10
10
10
  *
11
11
  * @param {Socker} socket
12
12
  * @param {Object} announcement
@@ -67,12 +67,12 @@ var SocketConduit = Function.inherits('Alchemy.Conduit', function Socket(socket,
67
67
  // Listen for disconnects
68
68
  socket.on('disconnect', function onDisconnect() {
69
69
 
70
- var key;
70
+ let key;
71
71
 
72
72
  that.emit('disconnect');
73
73
 
74
74
  for (key in that.linkups) {
75
- that.linkups[key].emit('disconnect');
75
+ that.linkups[key].destroy();
76
76
  }
77
77
  });
78
78
 
@@ -231,6 +231,8 @@ SocketConduit.setMethod(function onLinkup(packet) {
231
231
  // Create the new linkup instance
232
232
  linkup = new Linkup(this, type, id, packet.data);
233
233
 
234
+ linkup.submit('connected_to_server');
235
+
234
236
  if (typeof fnc === 'function') {
235
237
  fnc.call(this, this, linkup);
236
238
  } else if (typeof fnc === 'string') { // Strings like 'StaticController#index'
@@ -542,22 +544,55 @@ var Linkup = Function.inherits('Informer', function Linkup(conduit, type, id, da
542
544
 
543
545
  // Tell the client it's ready
544
546
  this.submit('ready');
547
+
548
+ this.on('__destroy__', () => {
549
+ this._destroy();
550
+ });
551
+ });
552
+
553
+ /**
554
+ * Add a reference to its scene_id
555
+ *
556
+ * @author Jelle De Loecker <jelle@elevenways.be>
557
+ * @since 1.3.10
558
+ * @version 1.3.10
559
+ */
560
+ Linkup.setProperty(function scene_id() {
561
+ return this.conduit?.scene_id;
545
562
  });
546
563
 
547
564
  /**
548
565
  * Destroy this link
549
566
  *
550
- * @author Jelle De Loecker <jelle@develry.be>
567
+ * @author Jelle De Loecker <jelle@elevenways.be>
551
568
  * @since 0.2.0
552
- * @version 1.1.4
569
+ * @version 1.3.10
553
570
  */
554
571
  Linkup.setMethod(function destroy() {
555
572
 
573
+ // Tell the client
574
+ this.submit('__destroy__');
575
+
576
+ // Actually do the destroying
577
+ this._destroy();
578
+
556
579
  // Remove all listeners
557
580
  this.removeAllListeners();
581
+ });
582
+
583
+ /**
584
+ * Make sure the linkup is removed
585
+ *
586
+ * @author Jelle De Loecker <jelle@elevenways.be>
587
+ * @since 1.3.10
588
+ * @version 1.3.10
589
+ */
590
+ Linkup.setMethod(function _destroy() {
558
591
 
559
- // Remove if from the linkups list
592
+ // Remove it from the linkups list
560
593
  delete this.conduit.linkups[this.id];
594
+
595
+ this.emit('destroyed');
561
596
  });
562
597
 
563
598
  /**
@@ -142,4 +142,15 @@ Info.setAction(function postponed(conduit, id) {
142
142
  }
143
143
 
144
144
  postponement.handleRequest(conduit);
145
+ });
146
+
147
+ /**
148
+ * Syncable link
149
+ *
150
+ * @author Jelle De Loecker <jelle@elevenways.be>
151
+ * @since 1.3.10
152
+ * @version 1.3.10
153
+ */
154
+ Info.setAction(function syncable(conduit, linkup, config) {
155
+ Classes.Alchemy.Syncable.handleLink(conduit, linkup, config);
145
156
  });
@@ -46,6 +46,30 @@ Router.setProperty(function current_url() {
46
46
  }
47
47
  });
48
48
 
49
+ /**
50
+ * Get the current riyte we're on
51
+ *
52
+ * @author Jelle De Loecker <jelle@elevenways.be>
53
+ * @since 1.3.10
54
+ * @version 1.3.10
55
+ *
56
+ * @type {Object}
57
+ */
58
+ Router.setProperty(function current_route() {
59
+
60
+ let route_name = this.view_render?.variables?.__route;
61
+
62
+ if (!route_name) {
63
+ return;
64
+ }
65
+
66
+ if (!this._all_routes) {
67
+ this._all_routes = alchemy.getRoutes();
68
+ }
69
+
70
+ return this._all_routes.get(route_name);
71
+ });
72
+
49
73
  /**
50
74
  * Check if the given URL is a local one
51
75
  *
@@ -98,14 +122,15 @@ Router.setMethod(function isLocalUrl(url) {
98
122
  */
99
123
  Router.setMethod(function applyDirective(element, name, options) {
100
124
 
101
- var config = this.routeConfig(name);
125
+ let config = this.routeConfig(name);
102
126
 
103
127
  if (!config) {
104
128
  this.markElementError(element, 'Route "' + name + '" not found');
105
129
  return;
106
130
  }
107
131
 
108
- let attribute_name,
132
+ let disable_ajax = false,
133
+ attribute_name,
109
134
  params = {},
110
135
  url;
111
136
 
@@ -190,6 +215,16 @@ Router.setMethod(function applyDirective(element, name, options) {
190
215
  element.setAttribute('hreflang', url._chosen_prefix);
191
216
  }
192
217
 
218
+ if (config && this.renderer.variables.__route) {
219
+ let route = this.current_route;
220
+
221
+ if (route && route.section != config.section) {
222
+ disable_ajax = true;
223
+ }
224
+ } else if (config.section != 'default') {
225
+ disable_ajax = true;
226
+ }
227
+
193
228
  if (element.role == 'link') {
194
229
  attribute_name = 'href';
195
230
  } else {
@@ -225,6 +260,10 @@ Router.setMethod(function applyDirective(element, name, options) {
225
260
  }
226
261
  }
227
262
 
263
+ if (disable_ajax) {
264
+ element.setAttribute('data-he-link', 'false');
265
+ }
266
+
228
267
  element.setAttribute(attribute_name, url);
229
268
  });
230
269
 
@@ -336,7 +375,7 @@ Router.setMethod(function routeConfig(name, socket_route) {
336
375
  *
337
376
  * @author Jelle De Loecker <jelle@elevenways.be>
338
377
  * @since 0.2.0
339
- * @version 1.3.7
378
+ * @version 1.3.10
340
379
  *
341
380
  * @param {String} name
342
381
  * @param {Object} parameters
@@ -345,8 +384,7 @@ Router.setMethod(function routeConfig(name, socket_route) {
345
384
  */
346
385
  Router.setMethod(function routeUrl(name, parameters, options) {
347
386
 
348
- var parameters,
349
- base_url,
387
+ var base_url,
350
388
  locales,
351
389
  config,
352
390
  url,
@@ -370,6 +408,17 @@ Router.setMethod(function routeUrl(name, parameters, options) {
370
408
  locales = [];
371
409
  }
372
410
 
411
+ if (parameters) {
412
+ // Create a shallow clone of simple objects
413
+ if (Object.isPlainObject(parameters)) {
414
+ parameters = {...parameters};
415
+ } else {
416
+ // Create an overlay instead of a clone
417
+ // (in case it's a special parameters object, like a Document)
418
+ parameters = Object.create(parameters);
419
+ }
420
+ }
421
+
373
422
  let chosen_prefix;
374
423
 
375
424
  if (config != null) {
@@ -744,7 +793,7 @@ Router.setMethod(function getRouteVariables() {
744
793
  let params,
745
794
  route,
746
795
  url;
747
-
796
+
748
797
  if (this.view_render?.variables?.__route) {
749
798
  route = this.view_render.variables.__route;
750
799
  params = this.view_render.variables.__urlparams;
@@ -16,7 +16,7 @@ function isStream(obj) {
16
16
  *
17
17
  * @author Jelle De Loecker <jelle@develry.be>
18
18
  * @since 0.2.0
19
- * @version 0.2.0
19
+ * @version 1.3.10
20
20
  *
21
21
  * @param {String} type
22
22
  */
@@ -54,7 +54,32 @@ var Linkup = Blast.Collection.Function.inherits('Informer', function ClientLinku
54
54
  } else {
55
55
  // Establish the link
56
56
  client._submit('linkup', {type: type, id: this.id, data: data});
57
+
58
+ // The server will send the `connected_to_server` event
59
+ this.on('connected_to_server', () => {
60
+ this.emit('ready');
61
+ });
57
62
  }
63
+
64
+ this.on('__destroy__', () => {
65
+ this._destroy();
66
+ });
67
+ });
68
+
69
+ /**
70
+ * Add a reference to its scene_id
71
+ *
72
+ * @author Jelle De Loecker <jelle@elevenways.be>
73
+ * @since 1.3.10
74
+ * @version 1.3.10
75
+ */
76
+ Linkup.setProperty(function scene_id() {
77
+
78
+ if (Blast.isBrowser) {
79
+ return hawkejs.scene?.scene_id;
80
+ }
81
+
82
+ return this.conduit?.scene_id;
58
83
  });
59
84
 
60
85
  /**
@@ -62,13 +87,13 @@ var Linkup = Blast.Collection.Function.inherits('Informer', function ClientLinku
62
87
  *
63
88
  * @author Jelle De Loecker <jelle@develry.be>
64
89
  * @since 0.2.0
65
- * @version 0.2.0
90
+ * @version 1.3.10
66
91
  *
67
92
  * @param {String} type
68
93
  * @param {Object} data
69
94
  * @param {Function} callback
70
95
  */
71
- Linkup.setMethod(function submit(type, data, stream, callback) {
96
+ Linkup.setAfterMethod('ready', function submit(type, data, stream, callback) {
72
97
  this.client.submit([this.id, type], data, stream, callback);
73
98
  });
74
99
 
@@ -117,14 +142,28 @@ Linkup.setMethod(function createStream() {
117
142
  });
118
143
 
119
144
  /**
120
- * Destroy this linkup
145
+ * Destroy this linkup (and tell the server)
121
146
  *
122
147
  * @author Jelle De Loecker <jelle@develry.be>
123
148
  * @since 0.2.0
124
- * @version 0.2.0
149
+ * @version 1.3.10
125
150
  */
126
151
  Linkup.setMethod(function destroy() {
152
+ this.submit('__destroy__');
153
+ this._destroy();
154
+ this.removeAllListeners();
155
+ });
156
+
157
+ /**
158
+ * Make sure the linkup is removed
159
+ *
160
+ * @author Jelle De Loecker <jelle@elevenways.be>
161
+ * @since 1.3.10
162
+ * @version 1.3.10
163
+ */
164
+ Linkup.setMethod(function _destroy() {
127
165
  delete this.client.linkups[this.id];
166
+ this.emit('destroyed');
128
167
  });
129
168
 
130
169
  /**
@@ -313,12 +352,19 @@ Client.setMethod(function createStream() {
313
352
  *
314
353
  * @author Jelle De Loecker <jelle@elevenways.be>
315
354
  * @since 0.2.0
316
- * @version 1.3.5
355
+ * @version 1.3.10
317
356
  *
318
357
  * @param {Function} callback
319
358
  */
320
359
  Client.setMethod(function connect(address, data, callback) {
321
360
 
361
+ // @TODO: Actual disconnects will cause problems
362
+ // (Though the library reconnects behind the scenes)
363
+ if (this.connected || this.hasBeenSeen('connecting')) {
364
+ this.afterOnce('connected', callback);
365
+ return;
366
+ }
367
+
322
368
  let that = this,
323
369
  io_client,
324
370
  serverstream,
@@ -584,14 +630,12 @@ Client.setMethod(function connect(address, data, callback) {
584
630
  */
585
631
  Client.setMethod(function linkup(type, data, cb) {
586
632
 
587
- var link;
588
-
589
633
  if (typeof data == 'function') {
590
634
  cb = data;
591
635
  data = {};
592
636
  }
593
637
 
594
- link = new Linkup(this, type, data);
638
+ let link = new Linkup(this, type, data);
595
639
 
596
640
  if (cb) {
597
641
  link.once('ready', function whenReady() {