@iebh/tera-fy 1.0.6 → 1.0.7

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.
@@ -236,7 +236,7 @@ export default class TeraFy {
236
236
  // Queue up event chain when document loads
237
237
  this.dom.iframe.setAttribute('sandbox', 'allow-downloads allow-scripts allow-same-origin');
238
238
  this.dom.iframe.addEventListener('load', ()=> {
239
- this.debug('TERA EMBED FRAME READY');
239
+ this.debug('Embed frame ready');
240
240
  resolve();
241
241
  });
242
242
 
@@ -304,7 +304,6 @@ export default class TeraFy {
304
304
  this.methods.forEach(method =>
305
305
  this[method] = this.rpc.bind(this, method)
306
306
  );
307
- this.debug('Remote methods installed:', this.methods);
308
307
  }
309
308
  // }}}
310
309
 
@@ -314,7 +313,7 @@ export default class TeraFy {
314
313
  * Debugging output function
315
314
  * This function will only act if `settings.devMode` is truthy
316
315
  *
317
- * @param {'INFO'|'LOG'|'WARN'|'ERROR'} [status] Optional prefixing level to mark the message as. 'WARN' and 'ERROR' will always show reguardless of devMode being enabled
316
+ * @param {'VERBOSE'|'INFO'|'LOG'|'WARN'|'ERROR'} [status] Optional prefixing level to mark the message as. 'WARN' and 'ERROR' will always show reguardless of devMode being enabled
318
317
  * @param {String} [msg...] Output to show
319
318
  */
320
319
  debug(...msg) {
@@ -134,6 +134,7 @@ export default class TeraFyServer {
134
134
  TERA: 1,
135
135
  ...cloneDeep(message), // Need to clone to resolve promise nasties
136
136
  };
137
+ this.debug('INFO', 'Parent reply', message, '<=>', payload);
137
138
  globalThis.parent.postMessage(payload, this.settings.restrictOrigin);
138
139
  } catch (e) {
139
140
  this.debug('ERROR', 'Attempted to dispatch payload server->client', payload);
@@ -169,10 +170,10 @@ export default class TeraFyServer {
169
170
  throw new Error('Unknown message format');
170
171
  }
171
172
  })
172
- .then(res => this.sendRaw({
173
+ .then(response => this.sendRaw({
173
174
  id: message.id,
174
175
  action: 'response',
175
- response: res,
176
+ response,
176
177
  }))
177
178
  .catch(e => {
178
179
  console.warn(`TERA-FY server threw on RPC:${message.method}:`, e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/tera-fy",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "TERA website worker",
5
5
  "scripts": {
6
6
  "dev": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.js --outfile=dist/terafy.js --minify --sourcemap --serve --servedir=.",
package/plugins/vue.js CHANGED
@@ -20,7 +20,7 @@ export default class TeraFyPluginVue extends TeraFyPluginBase {
20
20
  * @param {Boolean} [options.write=true] Allow local reactivity to writes - send these to the server
21
21
  * @param {Array<String>} Paths to subscribe to e.g. ['/users/'],
22
22
  *
23
- * @returns {Promies<Reactive<Object>>} A reactive object representing the project state
23
+ * @returns {Promie<Reactive<Object>>} A reactive object representing the project state
24
24
  */
25
25
  bindProjectState(options) {
26
26
  let settings = {
@@ -36,6 +36,8 @@ export default class TeraFyPluginVue extends TeraFyPluginBase {
36
36
  paths: settings.paths,
37
37
  }))
38
38
  .then(snapshot => {
39
+ this.debug('Got project snapshot', snapshot);
40
+
39
41
  // Create initial reactive
40
42
  let stateReactive = reactive(snapshot);
41
43
 
@@ -63,6 +65,40 @@ export default class TeraFyPluginVue extends TeraFyPluginBase {
63
65
  }
64
66
 
65
67
 
68
+ /**
69
+ * List of available projects for the current session
70
+ * @type {VueReactive<Array<Object>>}
71
+ */
72
+ projects = reactive([]);
73
+
74
+
75
+ /**
76
+ * The bound, reactive state of a Vue project
77
+ * When loaded this represents the state of a project as an object
78
+ * @type {Object}
79
+ */
80
+ state = null;
81
+
82
+
83
+ /**
84
+ * Promise used when binding to state
85
+ * @type {Promise}
86
+ */
87
+ statePromisable = null;
88
+
89
+
90
+ /**
91
+ * Utility function which returns an awaitable promise when the state is loading or being refreshed
92
+ * This is used in place of `statePromisable` as it has a slightly more logical syntax as a function
93
+ *
94
+ * @example Await the state loading
95
+ * await $tera.statePromise();
96
+ */
97
+ statePromise() {
98
+ return this.statePromisable;
99
+ }
100
+
101
+
66
102
  /**
67
103
  * Provide a Vue@3 compatible plugin
68
104
  */
@@ -90,15 +126,28 @@ export default class TeraFyPluginVue extends TeraFyPluginBase {
90
126
  ...options,
91
127
  };
92
128
 
129
+ // Bind $tera.state to the active project
130
+ // Initialize state to null
131
+ $tera.state = null;
132
+
133
+ // $tera.statePromisable becomes the promise we are waiting on to resolve
134
+ $tera.statePromisable = Promise.all([
135
+
136
+ // Bind available project and wait on it
137
+ $tera.bindProjectState(settings.stateOptions)
138
+ .then(state => $tera.state = state)
139
+ .then(()=> $tera.debug('INFO', 'Loaded project state', $tera.state)),
140
+
141
+ // Fetch available projects
142
+ // TODO: It would be nice if this was responsive to remote changes
143
+ $tera.getProjects()
144
+ .then(projects => $tera.projects = projects)
145
+ .then(()=> $tera.debug('INFO', 'Loaded projects', $tera.list)),
146
+ ])
147
+
148
+
93
149
  // Make this module available globally
94
150
  app.config.globalProperties[settings.globalName] = $tera;
95
-
96
- // Bind $tera.state to the active project
97
- // TODO: context.bindProjectState(settings.stateOptions),
98
- $tera.state = {
99
- id: 'TERAPROJ',
100
- name: 'A fake project',
101
- };
102
151
  },
103
152
 
104
153
  };