Skip to content

Commit 1e21b1e

Browse files
committed
add extra params to builder
1 parent 0d888a4 commit 1e21b1e

15 files changed

+101
-54
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ const builder = new Router(configRouter.rootPath, configRouter.useHash, configRo
2222
### After call the build method
2323

2424
```typescript
25-
builder.build(configRouter.routes, this.setPatch, null, element);
25+
builder.build(configRouter.routes, this.setPatch, null, element, extraParams);
2626
```
2727

2828
### Simple example with Ultradom 2
2929

3030
```typescript
3131
import { h, patch, VNode } from "ultradom";
32-
import { IRoutes, Router } from "spiel-builder";
32+
import { IRoutes, Router } from "../src";
3333
import { render } from "./render";
3434

3535
export type Keys = string;
@@ -45,8 +45,13 @@ export interface IRoutesExample extends IRoutes {
4545
page: IPage;
4646
}
4747

48+
export interface IAdditionalSetting {
49+
defaultProps: string;
50+
}
51+
4852
export interface IConfigRouter {
4953
rootPath?: string;
54+
defaultProps?: string;
5055
root?: string;
5156
useHash?: boolean;
5257
hash?: string;
@@ -65,7 +70,7 @@ export class ExampleBuilder {
6570
const element = this.createRootElement();
6671

6772
if (configRouter.routes) {
68-
this.builder.build(configRouter.routes, this.setPatch, null, element);
73+
this.builder.build(configRouter.routes, this.setPatch, null, element, configRouter.defaultProps);
6974
}
7075

7176
this.builder.router.resolve();
@@ -87,13 +92,15 @@ export class ExampleBuilder {
8792
return element;
8893
}
8994

90-
private setPatch(route: IRoutesExample, params: object, query: string, rootElement?: Element) {
95+
private setPatch(route: IRoutesExample, params: object, query: string,
96+
rootElement?: Element, defaultProps?: string) {
9197
const page = route.page;
9298
const state: State = {};
9399

94100
Object.assign(state, page.state);
95101
state.params = params;
96102
state.query = query;
103+
state.defaultProps = defaultProps;
97104
render(page.view, state, rootElement);
98105
}
99106
}

READMEAPI.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const builder = new Router(configRouter.rootPath, configRouter.useHash, configRo
1414
### After call the build method
1515

1616
```typescript
17-
builder.build(configRouter.routes, this.setPatch, null, element);
17+
builder.build(configRouter.routes, this.setPatch, null, element, extraParams);
1818
```
1919

2020
### Simple example with Ultradom 2
2121

2222
```typescript
2323
import { h, patch, VNode } from "ultradom";
24-
import { IRoutes, Router } from "spiel-builder";
24+
import { IRoutes, Router } from "../src";
2525
import { render } from "./render";
2626

2727
export type Keys = string;
@@ -37,8 +37,13 @@ export interface IRoutesExample extends IRoutes {
3737
page: IPage;
3838
}
3939

40+
export interface IAdditionalSetting {
41+
defaultProps: string;
42+
}
43+
4044
export interface IConfigRouter {
4145
rootPath?: string;
46+
defaultProps?: string;
4247
root?: string;
4348
useHash?: boolean;
4449
hash?: string;
@@ -57,7 +62,7 @@ export class ExampleBuilder {
5762
const element = this.createRootElement();
5863

5964
if (configRouter.routes) {
60-
this.builder.build(configRouter.routes, this.setPatch, null, element);
65+
this.builder.build(configRouter.routes, this.setPatch, null, element, configRouter.defaultProps);
6166
}
6267

6368
this.builder.router.resolve();
@@ -79,13 +84,15 @@ export class ExampleBuilder {
7984
return element;
8085
}
8186

82-
private setPatch(route: IRoutesExample, params: object, query: string, rootElement?: Element) {
87+
private setPatch(route: IRoutesExample, params: object, query: string,
88+
rootElement?: Element, defaultProps?: string) {
8389
const page = route.page;
8490
const state: State = {};
8591

8692
Object.assign(state, page.state);
8793
state.params = params;
8894
state.query = query;
95+
state.defaultProps = defaultProps;
8996
render(page.view, state, rootElement);
9097
}
9198
}

docs/classes/_router_.router.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ <h3>constructor</h3>
114114
<li class="tsd-description">
115115
<aside class="tsd-sources">
116116
<ul>
117-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/router.ts#L5">router.ts:5</a></li>
117+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/router.ts#L5">router.ts:5</a></li>
118118
</ul>
119119
</aside>
120120
<div class="tsd-comment tsd-typography">
@@ -159,7 +159,7 @@ <h3>router</h3>
159159
<div class="tsd-signature tsd-kind-icon">router<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Navigo</span></div>
160160
<aside class="tsd-sources">
161161
<ul>
162-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/router.ts#L5">router.ts:5</a></li>
162+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/router.ts#L5">router.ts:5</a></li>
163163
</ul>
164164
</aside>
165165
</section>
@@ -170,13 +170,13 @@ <h2>Methods</h2>
170170
<a name="build" class="tsd-anchor"></a>
171171
<h3>build</h3>
172172
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter">
173-
<li class="tsd-signature tsd-kind-icon">build&lt;Route&gt;<span class="tsd-signature-symbol">(</span>routes<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Route</span><span class="tsd-signature-symbol">[]</span>, builder<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">function</span>, parentPath<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">null</span>, rootElement<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">Element</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
173+
<li class="tsd-signature tsd-kind-icon">build&lt;Route&gt;<span class="tsd-signature-symbol">(</span>routes<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Route</span><span class="tsd-signature-symbol">[]</span>, builder<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">function</span>, parentPath<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">null</span>, rootElement<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">Element</span>, extraParams<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
174174
</ul>
175175
<ul class="tsd-descriptions">
176176
<li class="tsd-description">
177177
<aside class="tsd-sources">
178178
<ul>
179-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/router.ts#L24">router.ts:24</a></li>
179+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/router.ts#L25">router.ts:25</a></li>
180180
</ul>
181181
</aside>
182182
<div class="tsd-comment tsd-typography">
@@ -203,7 +203,7 @@ <h5>builder: <span class="tsd-signature-type">function</span></h5>
203203
<ul class="tsd-parameters">
204204
<li class="tsd-parameter-siganture">
205205
<ul class="tsd-signatures tsd-kind-type-literal tsd-is-not-exported">
206-
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span>route<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Route</span>, params<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">object</span>, query<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, rootElement<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">Element</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
206+
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span>route<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Route</span>, params<span class="tsd-signature-symbol">: </span><a href="../modules/_interfaces_.html#params" class="tsd-signature-type">Params</a>, query<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, rootElement<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">Element</span>, extraParams<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
207207
</ul>
208208
<ul class="tsd-descriptions">
209209
<li class="tsd-description">
@@ -213,14 +213,17 @@ <h4 class="tsd-parameters-title">Parameters</h4>
213213
<h5>route: <span class="tsd-signature-type">Route</span></h5>
214214
</li>
215215
<li>
216-
<h5>params: <span class="tsd-signature-type">object</span></h5>
216+
<h5>params: <a href="../modules/_interfaces_.html#params" class="tsd-signature-type">Params</a></h5>
217217
</li>
218218
<li>
219219
<h5>query: <span class="tsd-signature-type">string</span></h5>
220220
</li>
221221
<li>
222222
<h5><span class="tsd-flag ts-flagOptional">Optional</span> rootElement: <span class="tsd-signature-type">Element</span></h5>
223223
</li>
224+
<li>
225+
<h5><span class="tsd-flag ts-flagOptional">Optional</span> extraParams: <span class="tsd-signature-type">any</span></h5>
226+
</li>
224227
</ul>
225228
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
226229
</li>
@@ -240,6 +243,12 @@ <h5><span class="tsd-flag ts-flagOptional">Optional</span> rootElement: <span cl
240243
<p>the parent dom element where every route builds its page dom structure</p>
241244
</div>
242245
</li>
246+
<li>
247+
<h5><span class="tsd-flag ts-flagOptional">Optional</span> extraParams: <span class="tsd-signature-type">any</span></h5>
248+
<div class="tsd-comment tsd-typography">
249+
<p>Additional Params to allow add features to builder</p>
250+
</div>
251+
</li>
243252
</ul>
244253
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
245254
</li>

docs/index.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ <h3 id="first-instance-the-router-class-">First instance the Router class:</h3>
7373
<span class="hljs-keyword">const</span> builder = <span class="hljs-keyword">new</span> Router(configRouter.rootPath, configRouter.useHash, configRouter.hash);
7474
</code></pre>
7575
<h3 id="after-call-the-build-method">After call the build method</h3>
76-
<pre><code class="lang-typescript">builder.build(configRouter.routes, <span class="hljs-keyword">this</span>.setPatch, <span class="hljs-literal">null</span>, element);
76+
<pre><code class="lang-typescript">builder.build(configRouter.routes, <span class="hljs-keyword">this</span>.setPatch, <span class="hljs-literal">null</span>, element, extraParams);
7777
</code></pre>
7878
<h3 id="simple-example-with-ultradom-2">Simple example with Ultradom 2</h3>
7979
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> { h, patch, VNode } <span class="hljs-keyword">from</span> <span class="hljs-string">"ultradom"</span>;
80-
<span class="hljs-keyword">import</span> { IRoutes, Router } <span class="hljs-keyword">from</span> <span class="hljs-string">"spiel-builder"</span>;
80+
<span class="hljs-keyword">import</span> { IRoutes, Router } <span class="hljs-keyword">from</span> <span class="hljs-string">"../src"</span>;
8181
<span class="hljs-keyword">import</span> { render } <span class="hljs-keyword">from</span> <span class="hljs-string">"./render"</span>;
8282

8383
<span class="hljs-keyword">export</span> <span class="hljs-keyword">type</span> Keys = <span class="hljs-built_in">string</span>;
@@ -93,8 +93,13 @@ <h3 id="simple-example-with-ultradom-2">Simple example with Ultradom 2</h3>
9393
page: IPage;
9494
}
9595

96+
<span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> IAdditionalSetting {
97+
defaultProps: <span class="hljs-built_in">string</span>;
98+
}
99+
96100
<span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> IConfigRouter {
97101
rootPath?: <span class="hljs-built_in">string</span>;
102+
defaultProps?: <span class="hljs-built_in">string</span>;
98103
root?: <span class="hljs-built_in">string</span>;
99104
useHash?: <span class="hljs-built_in">boolean</span>;
100105
hash?: <span class="hljs-built_in">string</span>;
@@ -113,7 +118,7 @@ <h3 id="simple-example-with-ultradom-2">Simple example with Ultradom 2</h3>
113118
<span class="hljs-keyword">const</span> element = <span class="hljs-keyword">this</span>.createRootElement();
114119

115120
<span class="hljs-keyword">if</span> (configRouter.routes) {
116-
<span class="hljs-keyword">this</span>.builder.build(configRouter.routes, <span class="hljs-keyword">this</span>.setPatch, <span class="hljs-literal">null</span>, element);
121+
<span class="hljs-keyword">this</span>.builder.build(configRouter.routes, <span class="hljs-keyword">this</span>.setPatch, <span class="hljs-literal">null</span>, element, configRouter.defaultProps);
117122
}
118123

119124
<span class="hljs-keyword">this</span>.builder.router.resolve();
@@ -135,13 +140,15 @@ <h3 id="simple-example-with-ultradom-2">Simple example with Ultradom 2</h3>
135140
<span class="hljs-keyword">return</span> element;
136141
}
137142

138-
<span class="hljs-keyword">private</span> setPatch(route: IRoutesExample, params: object, query: <span class="hljs-built_in">string</span>, rootElement?: Element) {
143+
<span class="hljs-keyword">private</span> setPatch(route: IRoutesExample, params: object, query: <span class="hljs-built_in">string</span>,
144+
rootElement?: Element, defaultProps?: <span class="hljs-built_in">string</span>) {
139145
<span class="hljs-keyword">const</span> page = route.page;
140146
<span class="hljs-keyword">const</span> state: State = {};
141147

142148
<span class="hljs-built_in">Object</span>.assign(state, page.state);
143149
state.params = params;
144150
state.query = query;
151+
state.defaultProps = defaultProps;
145152
render(page.view, state, rootElement);
146153
}
147154
}

docs/interfaces/_interfaces_.igenerichooks.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> after</h3>
103103
<li class="tsd-description">
104104
<aside class="tsd-sources">
105105
<ul>
106-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L24">interfaces.ts:24</a></li>
106+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L25">interfaces.ts:25</a></li>
107107
</ul>
108108
</aside>
109109
<div class="tsd-comment tsd-typography">
@@ -139,7 +139,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> before</h3>
139139
<li class="tsd-description">
140140
<aside class="tsd-sources">
141141
<ul>
142-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L19">interfaces.ts:19</a></li>
142+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L20">interfaces.ts:20</a></li>
143143
</ul>
144144
</aside>
145145
<div class="tsd-comment tsd-typography">

docs/interfaces/_interfaces_.ihooks.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> after</h3>
105105
<li class="tsd-description">
106106
<aside class="tsd-sources">
107107
<ul>
108-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L38">interfaces.ts:38</a></li>
108+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L39">interfaces.ts:39</a></li>
109109
</ul>
110110
</aside>
111111
<div class="tsd-comment tsd-typography">
@@ -141,7 +141,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> already</h3>
141141
<li class="tsd-description">
142142
<aside class="tsd-sources">
143143
<ul>
144-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L44">interfaces.ts:44</a></li>
144+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L45">interfaces.ts:45</a></li>
145145
</ul>
146146
</aside>
147147
<h4 class="tsd-parameters-title">Parameters</h4>
@@ -164,7 +164,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> before</h3>
164164
<li class="tsd-description">
165165
<aside class="tsd-sources">
166166
<ul>
167-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L33">interfaces.ts:33</a></li>
167+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L34">interfaces.ts:34</a></li>
168168
</ul>
169169
</aside>
170170
<div class="tsd-comment tsd-typography">
@@ -224,7 +224,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> leave</h3>
224224
<li class="tsd-description">
225225
<aside class="tsd-sources">
226226
<ul>
227-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L43">interfaces.ts:43</a></li>
227+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L44">interfaces.ts:44</a></li>
228228
</ul>
229229
</aside>
230230
<div class="tsd-comment tsd-typography">

docs/interfaces/_interfaces_.iroutes.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> alias</h3>
101101
<div class="tsd-signature tsd-kind-icon">alias<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
102102
<aside class="tsd-sources">
103103
<ul>
104-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L51">interfaces.ts:51</a></li>
104+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L52">interfaces.ts:52</a></li>
105105
</ul>
106106
</aside>
107107
<div class="tsd-comment tsd-typography">
@@ -121,7 +121,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> hooks</h3>
121121
<div class="tsd-signature tsd-kind-icon">hooks<span class="tsd-signature-symbol">:</span> <a href="_interfaces_.ihooks.html" class="tsd-signature-type">IHooks</a></div>
122122
<aside class="tsd-sources">
123123
<ul>
124-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L57">interfaces.ts:57</a></li>
124+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L58">interfaces.ts:58</a></li>
125125
</ul>
126126
</aside>
127127
<div class="tsd-comment tsd-typography">
@@ -141,7 +141,7 @@ <h3>path</h3>
141141
<div class="tsd-signature tsd-kind-icon">path<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
142142
<aside class="tsd-sources">
143143
<ul>
144-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L53">interfaces.ts:53</a></li>
144+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L54">interfaces.ts:54</a></li>
145145
</ul>
146146
</aside>
147147
<div class="tsd-comment tsd-typography">
@@ -156,7 +156,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> routes</h3>
156156
<div class="tsd-signature tsd-kind-icon">routes<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div>
157157
<aside class="tsd-sources">
158158
<ul>
159-
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/ce5e358/src/interfaces.ts#L61">interfaces.ts:61</a></li>
159+
<li>Defined in <a href="https://github.com/spieljs/spiel-build/blob/0d888a4/src/interfaces.ts#L62">interfaces.ts:62</a></li>
160160
</ul>
161161
</aside>
162162
<div class="tsd-comment tsd-typography">

0 commit comments

Comments
 (0)