Skip to content

Commit db7e1eb

Browse files
committed
feat(property converters): helpers for deserializing attributes
1 parent 7d3db40 commit db7e1eb

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

README.md

+24-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ $ yarn add @rapid-build-ui/rb-base
3333
* [guid service](#guid-service)
3434
* [type service](#type-service)
3535
* [view directives](#view-directives)
36+
* [property converters](#properties-converters)
3637

3738
* [Slot Mixin](#slot-mixin) (adds helpers onto this for working with slots)
3839

@@ -43,7 +44,7 @@ $ yarn add @rapid-build-ui/rb-base
4344
/* Example
4445
**********/
4546
import { RbBase, props, html } from '../../rb-base/scripts/rb-base.js';
46-
import view from '../../rb-base/scripts/public/view/directives.js';
47+
import View from '../../rb-base/scripts/public/view/directives.js';
4748
import template from '../views/rb-popover.html';
4849

4950
export class RbPopover extends RbBase() {
@@ -122,6 +123,25 @@ const guid = Guid.create();
122123
```
123124

124125

126+
### property converters
127+
* Methods
128+
* valueless(val) :boolean
129+
130+
```js
131+
// Example
132+
import Converter from from '../../rb-base/scripts/public/props/converters.js';
133+
class RbIcon {
134+
static get props() {
135+
return {
136+
spin: Object.assign({}, props.boolean, {
137+
deserialize: Converter.valueless
138+
})
139+
};
140+
}
141+
}
142+
```
143+
144+
125145
### type service
126146
* Methods (**is.methods() :boolean**)
127147
* get(val) :string (returns val type)
@@ -152,13 +172,13 @@ to be used in view.
152172

153173
```js
154174
// Example
155-
import view from '../../rb-base/scripts/public/view/directives.js';
175+
import View from '../../rb-base/scripts/public/view/directives.js';
156176
```
157177

158178
```html
159-
<!-- Example (import view object in js, see "How To Use"): -->
179+
<!-- Example (import View object in js, see "How To Use"): -->
160180
<ul>
161-
${view.repeat(
181+
${View.repeat(
162182
['hulk','thor'],
163183
(hero, i) => html`<li>${i} ${hero}</li>`
164184
)}

src/client/scripts/private/services/view.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/********************************************************************
1+
/**********************************************************************
22
* VIEW SERVICE
3-
* -----------------------------------------------------------------
3+
* -------------------------------------------------------------------
44
* HOW TO USE
55
- import ViewService from './view.js';
6-
- this.rb.view = View.call(this); :object (set in constructor)
6+
- this.rb.view = ViewService.call(this); :object (set in constructor)
77
* API
88
- this.rb.view.isReady; :boolean (readonly: set in readyCallback())
99
- this.rb.view.readyCallback(); :void (run in rb-base's renderer())
10-
********************************************************************/
10+
**********************************************************************/
1111

1212
/* View Helper
1313
**************/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*******************************************
2+
* PROPERTY CONVERTERS
3+
* ----------------------------------------
4+
* HOW TO USE
5+
- import Converter from './converters.js';
6+
*******************************************/
7+
const Converters = {
8+
valueless(val) { // :boolean
9+
if (typeof val !== 'string') return val;
10+
val = val.trim();
11+
if (!val) return true; // valueless attr is empty string
12+
return /^true$/i.test(val);
13+
}
14+
};
15+
16+
/* Export it!
17+
*************/
18+
export default Converters;

0 commit comments

Comments
 (0)