@soleil-se/app-util 3.0.2 → 4.0.0

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/CHANGELOG.md CHANGED
@@ -4,8 +4,23 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [4.0.0] - 2021-01-27
8
+ A much needed major overhaul of the package.
9
+ See [MIGRATION](./MIGRATION.md).
10
+
11
+ ### Changed
12
+ - Major refactoring of package.
13
+ - Exports for render functions are moved.
14
+ - All documented constants and functions from base import (`@soleil-api/webapp-util`) now works both in a server and client context.
15
+
16
+ ### Removed
17
+ - `noScript` option in `render` (formerly `renderApp`) has been removed. If a no script message is needed use the `html` option wrapped in `<noscript>`.
18
+ - `@soleil-api/webapp-util/app-data` has been removed, use [getAppData](./README.md#getAppData) from `@soleil-api/webapp-util`.
19
+
20
+ ## [3.0.3] - 2020-11-03
21
+ - Nothing, Lerna wanted to publish...
22
+
7
23
  ## [3.0.2] - 2020-10-19
8
- ### Added
9
24
  - Nothing, Lerna wanted to publish...
10
25
 
11
26
  ## [3.0.1] - 2020-09-28
@@ -66,21 +81,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
81
  - `renderApp` is no longer using appName.
67
82
  - `render` is now called directly in `./app_src/client/index.js`.
68
83
  - `render` and `App` no longer needs to be exported from `./app_src/client/index.js`.
69
-
70
- ## [1.2.4] - 2020-12-12
71
- ### Fixed
72
- - `TypeError: Cannot call method getIdentifier of null` when app is viewed in Addons.
73
-
74
- ## [1.2.2] - 2019-05-20
75
- ### Fixed
76
- - Removed `_sitePage` from `currentPageId` in `getRouteUri`.
77
-
78
- ## [1.2.1] - 2019-05-09
79
- ### Added
80
- - Added timestamp to WebApp script tag to prevent cache when uploading a new version.
81
-
82
- ## [1.2.0] - 2019-05-07
83
- ### Changed
84
- - `getRouteUri` now returns the standalone route.
85
- - HTML comment to not include this.name in `renderApp`.
86
-
package/MIGRATION.md ADDED
@@ -0,0 +1,136 @@
1
+ # Migration
2
+
3
+ Migration from version 2 or 3 to 4.
4
+
5
+ <!-- TOC -->
6
+
7
+ - [renderApp](#renderapp)
8
+ - [renderTemplate](#rendertemplate)
9
+ - [getRouteUri](#getrouteuri)
10
+ - [AppData](#appdata)
11
+ - [Get data](#get-data)
12
+ - [Standard values](#standard-values)
13
+ - [Svelte](#svelte)
14
+ - [Server](#server)
15
+ - [Client](#client)
16
+ - [Vue](#vue)
17
+
18
+ <!-- /TOC -->
19
+
20
+ ## renderApp
21
+ Export moved and renamed.
22
+
23
+ Old:
24
+ ```js
25
+ import { renderApp } from '@soleil-api/webapp-util';
26
+ ```
27
+ New:
28
+ ```js
29
+ import { render } from '@soleil-api/webapp-util/server';
30
+ ```
31
+ ## renderTemplate
32
+ Export moved.
33
+
34
+ Old:
35
+ ```js
36
+ import { renderTemplate } from '@soleil-api/webapp-util';
37
+ ```
38
+ New:
39
+ ```js
40
+ import { renderTemplate } from '@soleil-api/webapp-util/server';
41
+ ```
42
+ ## getRouteUri
43
+ URIs for routes was previously passed as props when rendering an application. This is no longer needed.
44
+ Now you can use `getRouteUri` in a client context as well.
45
+
46
+ Old:
47
+ ```js
48
+ import AppData from '@soleil-api/webapp-util/app-data';
49
+
50
+ const getItems = async () => {
51
+ return fetch(AppData.itemsRoute)
52
+ .then((res) => res.json());
53
+ };
54
+ ```
55
+ New:
56
+ ```js
57
+ import { getRouteUri } from '@soleil-api/webapp-util';
58
+
59
+ const getItems = async () => {
60
+ return fetch(getRouteUri('/items'))
61
+ .then((res) => res.json());
62
+ };
63
+ ```
64
+ ## AppData
65
+
66
+ ### Get data
67
+ The default export as object and `@soleil-api/webapp-util/app-data` import is removed.
68
+
69
+ Old:
70
+ ```js
71
+ import AppData from '@soleil-api/webapp-util/app-data';
72
+
73
+ const { myValue } = AppData;
74
+ ```
75
+ New:
76
+ ```js
77
+ import { getAppData } from '@soleil-api/webapp-util';
78
+
79
+ // Get value with key
80
+ const myValue = getAppData('myValue');
81
+ // Or with destructuring
82
+ const { myValue } = getAppData();
83
+ ```
84
+ ### Standard values
85
+ Values that was set as sandard are now moved.
86
+
87
+ Old:
88
+ ```js
89
+ import AppData from '@soleil-api/webapp-util/app-data';
90
+
91
+ const { isOnline, isOffline, uniqueId } = AppData;
92
+ ```
93
+ New:
94
+ ```js
95
+ import { isOffline, isOnline, getNamespace } from '@soleil-api/webapp-util';
96
+
97
+ const uniqueId = getNamespace();
98
+ ```
99
+
100
+ ## Svelte
101
+ ### Server
102
+ Export moved.
103
+ Export `renderClient` is removed, use `render` from `'@soleil-api/webapp-util/server`
104
+
105
+ Old:
106
+ ```js
107
+ import { render } from '@soleil-api/webapp-util/svelte-server';
108
+ ```
109
+ New:
110
+ ```js
111
+ import { render } from '@soleil-api/webapp-util/server/svelte';
112
+ ```
113
+ ### Client
114
+ Export moved.
115
+
116
+ Old:
117
+ ```js
118
+ import { render } from '@soleil-api/webapp-util/svelte-client';
119
+ ```
120
+ New:
121
+ ```js
122
+ import { render } from '@soleil-api/webapp-util/client/svelte';
123
+ ```
124
+
125
+ ## Vue
126
+ Export moved.
127
+
128
+ Old:
129
+ ```js
130
+ import render from '@soleil-api/webapp-util/render-vue';
131
+ ```
132
+ New:
133
+ ```js
134
+ import { render } from '@soleil-api/webapp-util/client/vue';
135
+ ```
136
+
package/README.md CHANGED
@@ -1,329 +1,209 @@
1
- # Webapp Util
1
+ # `@soleil-se/webapp-util@^4.0.0`
2
2
  Utility functions for Webapps.
3
3
 
4
+ [GitHub](https://github.com/soleilit/server-monorepo/tree/master/packages/webapp-util)
5
+ [NPM](https://www.npmjs.com/package/@soleil-se/webapp-util)
6
+
4
7
  <!-- TOC -->
5
8
 
9
+ - [Requirements](#requirements)
6
10
  - [Install](#install)
7
- - [Changelog](#changelog)
8
- - [Migration 1.x.x to 2.x.x](#migration-1xx-to-2xx)
9
- - [Usage](#usage)
10
- - [`renderApp([config], [settings])` ⇒ `String`](#renderappconfig-settings-⇒-string)
11
- - [Example](#example)
12
- - [**Vue**](#vue)
13
- - [`getRouteUri(route)` `String`](#getrouteuriroute-⇒-string)
14
- - [Example](#example-1)
15
- - [`getViewUri(route)``String`](#getviewuriroute-⇒-string)
16
- - [Example](#example-2)
17
- - [`getResourceUri(resource)``String`](#getresourceuriresource-⇒-string)
18
- - [Example](#example-3)
19
- - [`renderTemplate(template, [values])` ⇒ `String`](#rendertemplatetemplate-values-⇒-string)
20
- - [Example](#example-4)
21
- - [`isOffline`](#isoffline)
22
- - [`isOnline`](#isonline)
23
- - [`uniqueId`](#uniqueid)
24
- - [AppData](#appdata)
25
- - [Svelte](#svelte)
26
- - [Server](#server)
27
- - [`render(App, [data], [settings])` ⇒ `String`](#renderapp-data-settings-⇒-string)
28
- - [`renderServer(App, [data])` ⇒ `String`](#renderserverapp-data-⇒-string)
29
- - [`renderClient(App, [data], [settings])` ⇒ `String`](#renderclientapp-data-settings-⇒-string)
30
- - [Client](#client)
31
- - [`render(App)`](#renderapp)
11
+ - [Migration](#migration)
12
+ - [API](#api)
13
+ - [Constants](#constants)
14
+ - [Functions](#functions)
15
+ - [appId : <code>String</code>](#appid--codestringcode)
16
+ - [isOffline : <code>Boolean</code>](#isoffline--codebooleancode)
17
+ - [isOnline : <code>Boolean</code>](#isonline--codebooleancode)
18
+ - [getNamespace([prefix]) ⇒ <code>String</code>](#getnamespaceprefix-⇒-codestringcode)
19
+ - [getRouteUri(route) ⇒ <code>String</code>](#getrouteuriroute-⇒-codestringcode)
20
+ - [getViewUri(route) ⇒ <code>String</code>](#getviewuriroute-⇒-codestringcode)
21
+ - [getResourceUri(resource) ⇒ <code>String</code>](#getresourceuriresource-⇒-codestringcode)
22
+ - [getAppData([key]) ⇒ <code>\*</code> \| <code>Object</code>](#getappdatakey-⇒-code\code-\-codeobjectcode)
23
+ - [Rendering](#rendering)
32
24
 
33
25
  <!-- /TOC -->
34
26
 
27
+ ## Requirements
28
+ `@soleil-se/sv-gulp-build` 4 or later (Works best with ^4.3.0).
29
+
35
30
  ## Install
36
31
  `yarn add @soleil-se/webapp-util`
37
32
 
38
- ## Changelog
39
- [See changelog](CHANGELOG.md).
33
+ ## Migration
34
+ Migrating from version 2 or 3?
35
+ See [MIGRATION](./MIGRATION.md).
40
36
 
41
- ## Migration 1.x.x to 2.x.x
37
+ ## API
38
+ All imports from base package are available both on the server and client.
42
39
 
43
- Now using `currentScript` to reference the script element the app is running in to pass data.
40
+ ### Constants
44
41
 
45
- Remove appName from the `renderApp` call in `./app_src/server/index.js`.
46
- Remove export of `App` and `render` and replace with a call to `render(App)` in `./app_src/client/index.js`.
42
+ <dl>
43
+ <dt><a href="#appId">appId</a> : <code>String</code></dt>
44
+ <dd><p>DOM friendly unique identifier for the WebApp.</p>
45
+ </dd>
46
+ <dt><a href="#isOffline">isOffline</a> : <code>Boolean</code></dt>
47
+ <dd><p>If the WebApp is running in offline mode or not.</p>
48
+ </dd>
49
+ <dt><a href="#isOnline">isOnline</a> : <code>Boolean</code></dt>
50
+ <dd><p>If the WebApp is running in online mode or not.</p>
51
+ </dd>
52
+ </dl>
47
53
 
48
- See [example](#example).
54
+ ### Functions
49
55
 
50
- ## Usage
51
- ```javascript
52
- import { renderApp, getRouteUri, getViewUri, getResourceUri, renderTemplate, isOffline, isOnline } from '@soleil-se/webapp-util';
53
- ```
54
- ### `renderApp([config], [settings])``String`
55
- Get HTML string for rendering a client side application.
56
- Can be used together with `@soleil-se/webapp-util/render-vue`, `@soleil-se/webapp-util/svelte-client` or a custom render function in the client code.
57
-
58
- **Returns**: <code>String</code> - HTML for rendering an application.
59
-
60
- | Param | Type | Default | Description |
61
- | --- | --- | --- | --- |
62
- | [config] | <code>Object</code> | <code>{}</code> | Server config or data that will be available in the attribute `data-app` on currentScript. In Vue it will also be available in the `$options` object. |
63
- | [settings] | <code>Object</code> | <code>{}</code> | Settings object. |
64
- | [settings.noScript] | <code>String</code> | <code>&#x27;&#x27;</code> | HTML that will be rendered when JavaScript is not available. |
65
- | [settings.selector] | <code>String</code> | <code>&#x60;[data-portlet-id&#x3D;&quot;${portletId}&quot;]&#x60;</code> | Query selector for where the app should be mounted. |
66
- | [settings.async] | <code>Boolean</code> | <code>false</code> | If the app script should be loaded asynchronously. [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/) |
67
- | [settings.defer] | <code>Boolean</code> | <code>true</code> | If the app script should be loaded after DOM is ready. [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/) |
68
- | [settings.req] | <code>Object</code> | | The req object from SiteVision, pass this to optimize browser specific script loading if you have multiple instances of the app. |
69
-
70
- #### Example
71
- In `app_src/server/index.js`.
72
- ```javascript
73
- router.get('/', (req, res) => {
74
- const data = { foo: 'bar' };
75
- // Most common usage.
76
- res.send(renderApp(data));
77
-
78
- // With all settings.
79
- res.send(renderApp(data, {
80
- noScript: 'You need JS for this!',
81
- selector: '#mount_me_here',
82
- async: false,
83
- defer: true,
84
- req,
85
- }));
86
- });
87
- ```
88
- ##### **Vue**
89
- In `app_src/client/index.js` or `app_src/main.js`.
90
- ```javascript
91
- import render from '@soleil-se/webapp-util/render-vue';
92
- import App from './App.vue';
56
+ <dl>
57
+ <dt><a href="#getNamespace">getNamespace([prefix])</a> ⇒ <code>String</code></dt>
58
+ <dd><p>Get a prefixed namespace unique for app.</p>
59
+ </dd>
60
+ <dt><a href="#getRouteUri">getRouteUri(route)</a><code>String</code></dt>
61
+ <dd><p>Get URI for a route, same as <code>getStandaloneUrl</code> in SiteVision template.</p>
62
+ </dd>
63
+ <dt><a href="#getViewUri">getViewUri(route)</a> ⇒ <code>String</code></dt>
64
+ <dd><p>Get URI for a view, same as <code>getUrl</code> in SiteVision template.</p>
65
+ </dd>
66
+ <dt><a href="#getResourceUri">getResourceUri(resource)</a> <code>String</code></dt>
67
+ <dd><p>Get URI for a resource.</p>
68
+ </dd>
69
+ <dt><a href="#getAppData">getAppData([key])</a> <code>*</code> | <code>Object</code></dt>
70
+ <dd><p>Get appData value or object.</p>
71
+ </dd>
72
+ </dl>
93
73
 
94
- render(App);
95
- ```
74
+ <a name="appId"></a>
96
75
 
97
- ### `getRouteUri(route)` `String`
98
- Get URI for a route, same as `getStandaloneUrl` in SiteVision template.
99
- https://developer.sitevision.se/docs/webapps/template#h-Methods
76
+ ### appId : <code>String</code>
77
+ DOM friendly unique identifier for the WebApp.
100
78
 
101
- **Returns**: <code>String</code> - URI for route.
79
+ ```js
80
+ import { appId } from '@soleil-se/webapp-util';
102
81
 
103
- | Param | Type | Description |
104
- | --- | --- | --- |
105
- | route | <code>String</code> | A route. |
82
+ console.log(appId); // For example: 12_682d461b1708a9bb1ea13efd
83
+ ```
84
+
85
+ <a name="isOffline"></a>
86
+
87
+ ### isOffline : <code>Boolean</code>
88
+ If the WebApp is running in offline mode or not.
106
89
 
90
+ ```js
91
+ import { isOffline } from '@soleil-se/webapp-util';
107
92
 
108
- #### Example
109
- ```javascript
110
- const routeUri = getRouteUri('/my-route');
93
+ console.log(isOffline); // true or false
111
94
  ```
112
- ### `getViewUri(route)` ⇒ `String`
113
- Get URI for a view, same as `getUrl` in SiteVision template.
114
- https://developer.sitevision.se/docs/webapps/template#h-Methods
115
95
 
116
- **Returns**: <code>String</code> - URI for view.
96
+ <a name="isOnline"></a>
117
97
 
118
- | Param | Type | Description |
119
- | --- | --- | --- |
120
- | route | <code>String</code> | A route. |
98
+ ### isOnline : <code>Boolean</code>
99
+ If the WebApp is running in online mode or not.
100
+
101
+ ```js
102
+ import { isOnline } from '@soleil-se/webapp-util';
121
103
 
122
- #### Example
123
- ```javascript
124
- const viewUri = getViewUri('/my-route');
104
+ console.log(isOnline); // true or false
125
105
  ```
126
106
 
127
- ### `getResourceUri(resource)``String`
128
- Get URI for a resource.
107
+ ### getNamespace([prefix]) ⇒ <code>String</code>
108
+ Get a prefixed namespace unique for app.
129
109
 
130
- **Returns**: `String` - URI for a resource.
110
+ **Returns**: <code>String</code> - Prefixed namespace.
131
111
 
132
- | Param | Type | Description |
112
+ | Param | Type | Default |
133
113
  | --- | --- | --- |
134
- | resource | `String` | A resource. |
114
+ | [prefix] | <code>string</code> | <code>&quot;&#x27;app&#x27;&quot;</code> |
135
115
 
116
+ ```js
117
+ import { getNamespace } from '@soleil-se/webapp-util';
136
118
 
137
- #### Example
138
- ```javascript
139
- const resourceUri = getResourceUri('file/in/resource.png');
140
- ```
141
- ### `renderTemplate(template, [values])` ⇒ `String`
142
- Renders a Underscore template and returns a string.
143
- This function is also available inside the template.
144
-
145
- **Returns**: `String` - Rendered template
146
-
147
- | Param | Type | Default | Description |
148
- | --- | --- | --- | --- |
149
- | template | `String` | | Underscore template. |
150
- | [values] | `Object` | `{}` | Values. |
151
-
152
- #### Example
153
- **Simple example**
154
- ```javascript
155
- const string = renderTemplate('<div><%= foo %></div>', {
156
- foo: 'bar',
157
- });
158
- ```
159
- **Multiple templates**
160
- ```html
161
- /* views/item.html */
162
- <li>
163
- <%- name %>
164
- </li>
165
- ```
166
- ```html
167
- /* views/main.html */
168
- <ul>
169
- <% items.forEach(function(item) { %>
170
- <%= renderTemplate(itemTemplate, item) %>
171
- <% }); %>
172
- </ul>
173
- ```
119
+ console.log(getNamespace());
120
+ // For example: app_12_682d461b1708a9bb1ea13efd
174
121
 
175
- ```javascript
176
- import { renderTemplate } from '@soleil-se/webapp-util';
177
- import mainTemplate from './views/main.html';
178
- import itemTemplate from './views/item.html';
122
+ console.log(getNamespace('input'));
123
+ // For example: input_12_682d461b1708a9bb1ea13efd
179
124
 
180
- const items = [{ name: 'Foo' }, { name: 'Bar' }, { name: 'Baz' }];
181
- const string = renderTemplate(mainTemplate, { items, itemTemplate });
182
- ```
183
- > **NOTE**
184
- > Remember that the second argument must be an object and that objects properties are accessed directly in any child templates!
185
- ### `isOffline`
186
- If the webapp is running in offline mode or not.
187
- This value is also passed to AppData.
188
-
189
- ```javascript
190
- if(isOffline) {
191
- // Do something
192
- }
125
+ // If the app is in a decoration template the Portlet ID is the same for all instances, so the ID of the decorated node is used as well.
126
+ console.log(getNamespace('decoration'));
127
+ // For example: decoration_10_3871c02f1754f3aa8f9d4eb_12_70c3d424173b4900fc550e1c
193
128
  ```
194
129
 
195
- ### `isOnline`
196
- If the webapp is running in online mode or not.
197
- This value is also passed to AppData.
130
+ <a name="getRouteUri"></a>
198
131
 
199
- ```javascript
200
- if(isOnline) {
201
- // Do something
202
- }
203
- ```
132
+ ### getRouteUri(route) ⇒ <code>String</code>
133
+ Get URI for a route, same as `getStandaloneUrl` in SiteVision template.
204
134
 
205
- ### `uniqueId`
206
- A unique ID for the WebApp.
207
- This value is also passed to AppData.
135
+ **Returns**: <code>String</code> - URI for route.
208
136
 
209
- ## AppData
210
- `@soleil-se/webapp-util/app-data`
211
- Data that is available for the WebApp.
212
- ```javascript
213
- import AppData from '@soleil-se/webapp-util/app-data';
137
+ | Param | Type | Description |
138
+ | --- | --- | --- |
139
+ | route | <code>String</code> | A route. |
214
140
 
215
- // These are avaliable per default:
216
- const { isOffline, isOnline, uniqueId } = AppData;
217
- ```
141
+ ```js
142
+ import { getRouteUri } from '@soleil-se/webapp-util';
218
143
 
219
- All data passed to the app is available in AppData:
220
- index.js
221
- ```javascript
222
- res.send(renderApp({ foo: 'bar' }))
144
+ console.log(getRouteUri('/items'));
145
+ // URI structure: /appresource/<pageId>/<portletId>/items
223
146
  ```
224
- In app:
225
- ```javascript
226
- import AppData from '@soleil-se/webapp-util/app-data';
227
147
 
228
- console.log(AppData.foo);
148
+ <a name="getViewUri"></a>
229
149
 
230
- // Or descructured
231
- const { foo } = AppData;
232
- console.log(foo);
233
- ```
150
+ ### getViewUri(route) ⇒ <code>String</code>
151
+ Get URI for a view, same as `getUrl` in SiteVision template.
234
152
 
235
- ## Svelte
236
- Functions for rendering a Svelte application.
237
-
238
- ### Server
239
- `@soleil-se/webapp-util/svelte-server`
240
- #### `render(App, [data], [settings])` ⇒ `String`
241
- Get HTML string for rendering a universal Svelte application.
242
- To be used together with `@soleil-se/webapp-util/svelte-client`.
243
-
244
- **Returns**: <code>String</code> - HTML for rendering an application.
245
-
246
- | Param | Type | Default | Description |
247
- | --- | --- | --- | --- |
248
- | [App] | <code>Svelte</code> | | Svelte application. |
249
- | [data] | <code>Object</code> | <code>{}</code> | Server data or config that will be available from `@soleil-se/webapp-util/app-data` |
250
- | [settings] | <code>Object</code> | <code>{}</code> | Settings object. |
251
- | [settings.async] | <code>Boolean</code> | <code>false</code> | If the app script should be loaded asynchronously. [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/) |
252
- | [settings.defer] | <code>Boolean</code> | <code>true</code> | If the app script should be loaded after DOM is ready. [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/) |
253
- | [settings.req] | <code>Object</code> | | The req object from SiteVision, pass this to optimize browser specific script loading if you have multiple instances of the app. |
254
-
255
- In `app_src/server/index.js` or `app_src/index.js`.
256
- ```javascript
257
- import router from 'router';
258
- import { render } from '@soleil-se/webapp-util/svelte-server';
259
-
260
- import App from './App.svelte';
261
-
262
- router.get('/', (req, res) => {
263
- const data = { foo: 'bar' };
264
- res.send(renderSvelte(App, data));
265
- });
266
- ```
153
+ **Returns**: <code>String</code> - URI for view.
154
+
155
+ | Param | Type | Description |
156
+ | --- | --- | --- |
157
+ | route | <code>String</code> | A route. |
267
158
 
268
- #### `renderServer(App, [data])` ⇒ `String`
269
- Get HTML string for a server only rendered Svelte application.
159
+ ```js
160
+ import { getViewUri } from '@soleil-se/webapp-util';
270
161
 
271
- **Returns**: <code>String</code> - HTML for rendering an application.
162
+ console.log(getViewUri('/items'));
163
+ // URI structure: ?sv.target=<id>&sv.<id>.route=/items
164
+ ```
272
165
 
273
- | Param | Type | Default | Description |
274
- | --- | --- | --- | --- |
275
- | [App] | <code>Svelte</code> | | Svelte application. |
276
- | [data] | <code>Object</code> | <code>{}</code> | Server data or config that will be available from `@soleil-se/webapp-util/app-data` |
166
+ <a name="getResourceUri"></a>
167
+ ### getResourceUri(resource) <code>String</code>
168
+ Get URI for a resource.
277
169
 
278
- In `app_src/server/index.js` or `app_src/index.js`.
279
- ```javascript
280
- import router from 'router';
281
- import { renderServer } from '@soleil-se/webapp-util/svelte-server';
170
+ **Returns**: <code>String</code> - URI for a resource.
282
171
 
283
- import App from './App.svelte';
172
+ | Param | Type | Description |
173
+ | --- | --- | --- |
174
+ | resource | <code>String</code> | A resource. |
175
+
176
+ ```js
177
+ import { getResourceUri } from '@soleil-se/webapp-util';
284
178
 
285
- router.get('/', (req, res) => {
286
- const data = { foo: 'bar' };
287
- res.send(renderServer(App, data));
288
- });
179
+ console.log(getResourceUri('/image.png'));
180
+ // URI structure: /webapp-files/<webappname>/<webappversion>/image.png
289
181
  ```
290
182
 
291
- #### `renderClient(App, [data], [settings])` ⇒ `String`
292
- Get HTML string for a client only rendered Svelte application.
293
- Can be used together with `@soleil-se/webapp-util/svelte-client`.
183
+ <a name="getAppData"></a>
294
184
 
295
- **Returns**: <code>String</code> - HTML for rendering an application.
185
+ ### getAppData([key]) ⇒ <code>\*</code> \| <code>Object</code>
186
+ Get appData value or object that is passed to app when rendering.
296
187
 
297
- | Param | Type | Default | Description |
298
- | --- | --- | --- | --- |
299
- | [App] | <code>Svelte</code> | | Svelte application. |
300
- | [data] | <code>Object</code> | <code>{}</code> | Server data or config that will be available from `@soleil-se/webapp-util/app-data` |
301
- | [settings] | <code>Object</code> | <code>{}</code> | Settings object. |
302
- | [settings.async] | <code>Boolean</code> | <code>false</code> | If the app script should be loaded asynchronously. [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/) |
303
- | [settings.defer] | <code>Boolean</code> | <code>true</code> | If the app script should be loaded after DOM is ready. [Read more about async and defer.](https://flaviocopes.com/javascript-async-defer/) |
304
- | [settings.req] | <code>Object</code> | | The req object from SiteVision, pass this to optimize browser specific script loading if you have multiple instances of the app. |
188
+ **Returns**: <code>\*</code> \| <code>Object</code> - Value or object.
305
189
 
306
- In `app_src/server/index.js` or `app_src/index.js`.
307
- ```javascript
308
- import router from 'router';
309
- import { renderClient } from '@soleil-se/webapp-util/svelte-server';
190
+ | Param | Type | Description |
191
+ | --- | --- | --- |
192
+ | [key] | <code>String</code> | Key for value. |
310
193
 
311
- import App from './App.svelte';
194
+ ```js
195
+ import { getAppData } from '@soleil-se/webapp-util';
312
196
 
313
- router.get('/', (req, res) => {
314
- const data = { foo: 'bar' };
315
- res.send(renderSvelte(App, data));
316
- });
197
+ // Get value with key
198
+ const myValue = getAppData('myValue');
199
+ // Or with destructuring
200
+ const { myValue } = getAppData();
317
201
  ```
318
202
 
319
- ### Client
320
- `@soleil-se/webapp-util/svelte-client`
321
- #### `render(App)`
322
- In `app_src/client/index.js` or `app_src/main.js`.
323
- ```javascript
324
- import { render } from '@soleil-se/webapp-util/svelte-client';
325
- import App from './App.svelte';
203
+ ## Rendering
326
204
 
327
- render(App);
328
- ```
205
+ * [Render](./docs/1.render.md)
206
+ * [Svelte](./docs/2.svelte.md)
207
+ * [Vue](./docs/3.vue.md)
208
+ * [Underscore](./docs/4.underscore.md)
329
209