vsn 0.1.117 → 0.1.118

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.
Files changed (41) hide show
  1. package/demo/service.html +2 -1
  2. package/demo/vsn.js +2 -2
  3. package/demo/xhr-test.html +8 -2
  4. package/dist/AST/XHRNode.js +4 -1
  5. package/dist/AST/XHRNode.js.map +1 -1
  6. package/dist/Scope/ScopeDataAbstract.d.ts +2 -0
  7. package/dist/Scope/ScopeDataAbstract.js +4 -0
  8. package/dist/Scope/ScopeDataAbstract.js.map +1 -1
  9. package/dist/Scope/properties/Property.d.ts +1 -0
  10. package/dist/Scope/properties/Property.js +22 -1
  11. package/dist/Scope/properties/Property.js.map +1 -1
  12. package/dist/attributes/Exec.d.ts +1 -0
  13. package/dist/attributes/Exec.js +21 -3
  14. package/dist/attributes/Exec.js.map +1 -1
  15. package/dist/attributes/XHRAttribute.js +18 -1
  16. package/dist/attributes/XHRAttribute.js.map +1 -1
  17. package/dist/contrib/XHR.d.ts +21 -0
  18. package/dist/contrib/XHR.js +78 -0
  19. package/dist/contrib/XHR.js.map +1 -0
  20. package/dist/contrib/_imports.d.ts +1 -0
  21. package/dist/contrib/_imports.js +6 -0
  22. package/dist/contrib/_imports.js.map +1 -0
  23. package/dist/demo/ServiceDemo.d.ts +1 -1
  24. package/dist/demo/ServiceDemo.js +42 -1
  25. package/dist/demo/ServiceDemo.js.map +1 -1
  26. package/dist/demo.min.js +3 -0
  27. package/dist/demo.min.js.LICENSE.txt +9 -0
  28. package/dist/version.d.ts +1 -1
  29. package/dist/version.js +1 -1
  30. package/dist/vsn.min.js +3 -0
  31. package/dist/vsn.min.js.LICENSE.txt +9 -0
  32. package/package.json +1 -1
  33. package/src/AST/XHRNode.ts +4 -1
  34. package/src/Scope/ScopeDataAbstract.ts +8 -0
  35. package/src/Scope/properties/Property.ts +23 -0
  36. package/src/attributes/Exec.ts +9 -1
  37. package/src/attributes/XHRAttribute.ts +19 -0
  38. package/src/contrib/XHR.ts +46 -0
  39. package/src/contrib/_imports.ts +1 -0
  40. package/src/demo/ServiceDemo.ts +1 -1
  41. package/src/version.ts +1 -1
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ * Code distributed by Google as part of the polymer project is also
8
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.117",
3
+ "version": "0.1.118",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -48,7 +48,10 @@ export class XHRNode extends Node implements TreeNode {
48
48
  }
49
49
 
50
50
  let request = {
51
- method: method
51
+ method: method,
52
+ headers: {
53
+ 'X-Requested-With': 'XMLHttpRequest'
54
+ }
52
55
  };
53
56
 
54
57
  if (request.method === 'GET') {
@@ -8,6 +8,7 @@ export interface IScopeData {
8
8
  export class ScopeDataAbstract extends EventDispatcher {
9
9
  [key: string]: any;
10
10
  __properties__: string[];
11
+ __methods__: string[];
11
12
  protected _lastData: any;
12
13
 
13
14
  constructor() {
@@ -16,6 +17,13 @@ export class ScopeDataAbstract extends EventDispatcher {
16
17
  // Objects may have __properties__ from prototype
17
18
  if(!this['__properties__'])
18
19
  this.__properties__ = [];
20
+
21
+ if(!this['__methods__'])
22
+ this.__methods__ = [];
23
+ }
24
+
25
+ createMethod(name: string, method: (...args: any[]) => any) {
26
+
19
27
  }
20
28
 
21
29
  createProperty(name: string, propertyType: any = Property, config?: IPropertyConfig): any {
@@ -24,6 +24,29 @@ export function property(propertyType = Property, config: {} | null = {}) {
24
24
  }
25
25
  }
26
26
 
27
+ export function method(config: {} | null = {}) {
28
+ return function(target: any, key: string) {
29
+ if(target.__methods__ == undefined) {
30
+ target.__methods__ = [];
31
+ }
32
+
33
+ // Abstract/extended classes share __properties__
34
+ if(target.__methods__.indexOf(key) == -1)
35
+ target.__methods__.push(key);
36
+
37
+ const getter = function() {
38
+ return config;
39
+ };
40
+
41
+ Object.defineProperty(target, '__'+key+'__', {
42
+ get: getter,
43
+ set: v => {},
44
+ enumerable:false,
45
+ configurable: true
46
+ });
47
+ }
48
+ }
49
+
27
50
  export type TValidator = (value: any) => string[];
28
51
 
29
52
  export interface IPropertyConfig {
@@ -18,7 +18,15 @@ export class Exec extends Attribute {
18
18
  }
19
19
 
20
20
  public async extract() {
21
- await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
21
+ if (this.hasModifier('defer')) {
22
+ this.tag.dom.once('built', () => this.execute());
23
+ } else {
24
+ await this.execute();
25
+ }
22
26
  await super.extract();
23
27
  }
28
+
29
+ public async execute() {
30
+ await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
31
+ }
24
32
  }
@@ -2,6 +2,7 @@ import {Registry} from "../Registry";
2
2
  import {Attribute} from "../Attribute";
3
3
  import {Tree} from "../AST";
4
4
  import {VisionHelper} from "../helpers/VisionHelper";
5
+ import {XHR} from "../contrib/XHR";
5
6
 
6
7
  @Registry.attribute('vsn-xhr')
7
8
  export class XHRAttribute extends Attribute {
@@ -61,12 +62,30 @@ export class XHRAttribute extends Attribute {
61
62
  } else if (this.isAnchor) {
62
63
  url = this.tag.element.getAttribute('href');
63
64
  method = this.getAttributeBinding('GET');
65
+ method = method.toUpperCase();
66
+ if (['POST', 'PUT'].indexOf(method) > -1) {
67
+ formData = new FormData();
68
+ }
64
69
  }
65
70
 
66
71
  this.request.addEventListener('loadend', this.handleXHREvent.bind(this));
67
72
  this.request.addEventListener('error', this.handleXHREvent.bind(this));
68
73
  this.request.open(method, url);
69
74
  this.request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
75
+ const siteHeaders = XHR.instance.getHeaders();
76
+ for (const key in siteHeaders) {
77
+ this.request.setRequestHeader(key, siteHeaders[key]);
78
+ }
79
+
80
+ if (formData instanceof FormData) {
81
+ const siteFormData = XHR.instance.getFormData();
82
+ if (siteFormData) {
83
+ for (const key in siteFormData) {
84
+ formData.append(key, siteFormData[key]);
85
+ }
86
+ }
87
+ }
88
+
70
89
  this.request.send(formData);
71
90
  }
72
91
 
@@ -0,0 +1,46 @@
1
+ import {Registry} from "../Registry";
2
+ import {Service} from "../Service";
3
+ import {property} from "../Scope/properties/Property";
4
+
5
+ @Registry.service('XHR')
6
+ export class XHR extends Service {
7
+ @property()
8
+ public readonly siteHeaders: { [key: string]: {[key: string]: string}} = {};
9
+
10
+ @property()
11
+ public readonly siteFormData: { [key: string]: {[key: string]: string}} = {};
12
+
13
+ public addHeader(key: string, value: string, site: string = null) {
14
+ if (site === null)
15
+ site = window.location.hostname;
16
+
17
+ if (!this.siteHeaders[site]) {
18
+ this.siteHeaders[site] = {};
19
+ }
20
+ this.siteHeaders[site][key] = value;
21
+ }
22
+
23
+ public addFormData(key: string, value: string, site: string = null) {
24
+ if (site === null)
25
+ site = window.location.hostname;
26
+
27
+ if (!this.siteFormData[site]) {
28
+ this.siteFormData[site] = {};
29
+ }
30
+ this.siteFormData[site][key] = value;
31
+ }
32
+
33
+ public getHeaders(site: string = null) {
34
+ if (site === null)
35
+ site = window.location.hostname;
36
+
37
+ return this.siteHeaders[site];
38
+ }
39
+
40
+ public getFormData(site: string = null) {
41
+ if (site === null)
42
+ site = window.location.hostname;
43
+
44
+ return this.siteFormData[site];
45
+ }
46
+ }
@@ -0,0 +1 @@
1
+ export {XHR} from "./XHR";
@@ -5,7 +5,7 @@ export class ServiceDemo extends Service {
5
5
  @property(IntegerProperty)
6
6
  public count: number = 0;
7
7
 
8
- add(num: number): number {
8
+ async add(num: number=1): Promise<number> {
9
9
  return this.count += num;
10
10
  }
11
11
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.117';
1
+ export const VERSION = '0.1.118';
2
2