0.0.133 • Published 1 year ago
@rhtml/component v0.0.133
Strange component representing more functional approach of defining decorators
import { DefineDependencies, Component } from '@rhtml/component';
import { Container, Injectable } from '@rxdi/core';
import { html, LitElement, property } from '@rxdi/lit-html';
import { interval } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable()
class CounterService {
counter = 55;
}
const Providers = DefineDependencies(CounterService)(Container);
@Component<{ counter: number }, typeof Providers, CounterComponent>({
Settings: {
selector: 'counter-component'
},
Providers,
State: function(this, [counterService]) {
return interval(1000).pipe(
map(value => ({ counter: this.counter + counterService.counter + value }))
);
},
Render: ([counterService]) =>
function(this, { counter }) {
return html`
${counter} ${counterService.counter}
`;
}
})
export class CounterComponent extends LitElement {
@property({ type: Number })
counter: number;
}
/*
<counter-component .counter=${1000}></counter-component>
*/
Functional composition
import { Partial } from '@rhtml/component';
const compose = <T, D = []>(selector: string, styles?: CSSResult[], deps?: D) =>
Partial<T, D>({
selector,
styles
})(deps);
const state = () => interval(1000).pipe(map(() => new Date().getSeconds()));
@(compose<number>('date-component')(state)(() => date => date))
export class DateComponent extends LitElement {}
@(compose<number, typeof Dependencies>(
'date-component2',
null,
Dependencies
)(([appService]) => state().pipe(map(res => res)))(() => date => date))
export class DateComponent2 extends LitElement {}
@(compose<number>('date-component3')(state)(() => date =>
html`
${date}
`
))
export class DateComponent3 extends LitElement {}
Usage inside DOM
<date-component></date-component>
<date-component2></date-component2>
<date-component3></date-component3>
import { Component } from '@rhtml/component';
/**
* @customElement counter-component
*/
@Component<{ counter: number }, [], CounterComponent>({
Settings: {
selector: 'counter-component',
style: css`
.counter {
background: red;
color: white;
}
`
},
Providers: [],
State: function(this) {
return combineLatest([this.counter, this.mega]).pipe(
map(([value, v2]) => ({ counter: value + v2 }))
);
},
Render: () =>
function(this, { counter }, setState) {
return html`
<p>${counter}</p>
<button @click=${() => setState({ counter: counter + counter })}>
CLICK ME
</button>
`;
}
})
export class CounterComponent extends LitElement {
@property({ type: Object })
counter: Observable<number>;
@property({ type: Object })
mega: Observable<number>;
}
import { Component, DefineDependencies } from '@rhtml/component';
@Component({
Settings: {
selector: 'date-component'
},
Providers: DefineDependencies(AppsService, SocialService)(Container),
State: ([appService, socialService]) =>
interval(1000).pipe(map(() => new Date().getSeconds())),
Render: ([appService, socialService]) => seconds => seconds
})
export class ComposableComponent extends LitElement {}
0.0.133
1 year ago
0.0.131
1 year ago
0.0.132
1 year ago
0.0.129
1 year ago
0.0.130
1 year ago
0.0.128
1 year ago
0.0.127
1 year ago
0.0.126
1 year ago
0.0.125
2 years ago
0.0.120
2 years ago
0.0.124
2 years ago
0.0.123
2 years ago
0.0.122
2 years ago
0.0.121
2 years ago
0.0.119
2 years ago
0.0.118
2 years ago
0.0.117
3 years ago
0.0.116
3 years ago
0.0.115
3 years ago
0.0.114
3 years ago
0.0.113
3 years ago
0.0.112
3 years ago
0.0.111
3 years ago
0.0.87
3 years ago
0.0.88
3 years ago
0.0.89
3 years ago
0.0.110
3 years ago
0.0.106
3 years ago
0.0.95
3 years ago
0.0.105
3 years ago
0.0.96
3 years ago
0.0.104
3 years ago
0.0.97
3 years ago
0.0.103
3 years ago
0.0.98
3 years ago
0.0.99
3 years ago
0.0.109
3 years ago
0.0.108
3 years ago
0.0.107
3 years ago
0.0.90
3 years ago
0.0.102
3 years ago
0.0.91
3 years ago
0.0.101
3 years ago
0.0.92
3 years ago
0.0.100
3 years ago
0.0.93
3 years ago
0.0.94
3 years ago
0.0.85
4 years ago
0.0.86
4 years ago
0.0.84
4 years ago
0.0.83
4 years ago
0.0.81
4 years ago
0.0.82
4 years ago
0.0.75
5 years ago
0.0.76
4 years ago
0.0.77
4 years ago
0.0.78
4 years ago
0.0.79
4 years ago
0.0.80
4 years ago
0.0.74
5 years ago
0.0.73
5 years ago
0.0.72
5 years ago
0.0.71
5 years ago
0.0.70
5 years ago
0.0.69
5 years ago