-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fastify): documentation fix and publish version
- Loading branch information
1 parent
1903a35
commit c8dcc18
Showing
26 changed files
with
194 additions
and
3,059 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
// Specifies the ESLint parser | ||
parser: "@typescript-eslint/parser", | ||
extends: [ | ||
// Uses the recommended rules from the @typescript-eslint/eslint-plugin | ||
"plugin:@typescript-eslint/recommended", | ||
// Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier | ||
"prettier/@typescript-eslint", | ||
// Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. | ||
"plugin:prettier/recommended" | ||
], | ||
parserOptions: { | ||
// Allows for the parsing of modern ECMAScript features | ||
ecmaVersion: 2018, | ||
// Allows for the use of imports | ||
sourceType: "module" | ||
}, | ||
rules: { | ||
"@typescript-eslint/explicit-function-return-type": 0, | ||
"simple-import-sort/sort": "error", | ||
"sort-imports": "off", | ||
"import/order": "off", | ||
"@typescript-eslint/camelcase": 0, | ||
"no-use-before-define": "off", | ||
"@typescript-eslint/no-use-before-define": "off", | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": ["off"], | ||
}, | ||
plugins: ["simple-import-sort"], | ||
ignorePatterns: ['dist', './packages/schematics', 'module'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,5 @@ coverage | |
|
||
dist | ||
|
||
*.js | ||
*.map.js | ||
*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
## [0.0.69] - 2020-12-13 | ||
|
||
### Added | ||
- New package with name `@rhtml/component` [Documentation](./packages/component/README.md) | ||
|
||
- New package with name `@rhtml/fastify` [Documentation](./packages/fastify/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,257 +1,7 @@ | ||
# Reactive HTML | ||
# Reactive HTML Core packages intended for framework creation | ||
|
||
### Packages | ||
|
||
| Package | Description | | ||
| ------------------------------------------------------ | ---------------------------------------------------------------------- | | ||
| [@rhtml/di](packages/di) | IOC container | | ||
| [@rhtml/component](packages/component) | Main reactive component for building UI | | ||
| [@rhtml/components](packages/components) | Declarative monadic approach defining WC using html | | ||
| [@rhtml/operators](packages/operators) | Useful declarative operators like `for` `if` | | ||
| [@rhtml/graphql](packages/graphql) | Declarative Graphql for executing `query` `mutation` or `subscription` | | ||
| [@rhtml/hooks](packages/hooks) | React like hooks for use inside web components | | ||
| [@rhtml/renderer](packages/renderer) | Main renderer for every component used also with observables | | ||
| [@rhtml/schematics](packages/schematics) | Angular like schematics for component generation using DI container | | ||
| [@rhtml/experiments](packages/experiments) | Declarative way of defining web components only with HTML | | ||
| [@rhtml/decorators](packages/decorators) | Useful decorators @HostListener and @Input | | ||
| [@rhtml/modifiers](packages/modifiers) | Modifiers created using Custom HTML Attributes | | ||
| [@rhtml/custom-attributes](packages/custom-attributes) | Create your own custom Attributes | | ||
|
||
#### Installation | ||
|
||
```bash | ||
npm i @rhtml/operators @rhtml/components @rhtml/hooks @rhtml/graphql | ||
``` | ||
|
||
#### Usage | ||
|
||
```typescript | ||
import { LitElement, Component, html } from '@rxdi/lit-html'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { delay } from 'rxjs/operators'; | ||
|
||
import '@rhtml/operators'; | ||
import '@rhtml/components'; | ||
import '@rhtml/hooks'; | ||
import '@rhtml/graphql'; | ||
|
||
interface State { | ||
counter: number; | ||
} | ||
interface NotificationState { | ||
data: { notifications: { appUpdated: string | number } }; | ||
} | ||
@Component({ | ||
selector: 'r-html-view', | ||
template(this: RHtmlViewComponent) { | ||
return html` | ||
<r-renderer | ||
.options=${{ | ||
state: new BehaviorSubject({ counter: 1 }).pipe(delay(1700)), | ||
render: (res: State, setState: (res: State) => State) => | ||
html` | ||
<button | ||
@click=${() => setState({ counter: res.counter + res.counter })} | ||
> | ||
Increment | ||
</button> | ||
${res.counter} | ||
`, | ||
loading: () => | ||
html` | ||
Loading... | ||
`, | ||
error: () => | ||
html` | ||
Error | ||
` | ||
}} | ||
></r-renderer> | ||
<r-for .of=${['IterableItem 1', 'Iterable Item 2']}> | ||
<r-let | ||
.item=${v => html` | ||
${v} | ||
`} | ||
></r-let> | ||
</r-for> | ||
<r-part> | ||
<r-state .value=${'Kristiyan Tachev'}></r-state> | ||
<r-render | ||
.state=${name => html` | ||
<p>${name}</p> | ||
`} | ||
> | ||
</r-render> | ||
</r-part> | ||
<r-part> | ||
<r-settings .value=${{ fetchPolicy: 'cache-first' }}></r-settings> | ||
<r-fetch .query=${`{ continents { name } }`}></r-fetch> | ||
<r-render | ||
.state=${({ data: { continents } }) => html` | ||
<r-for .of=${continents}> | ||
<r-let .item=${({ name }) => name}></r-let> | ||
</r-for> | ||
`} | ||
> | ||
</r-render> | ||
</r-part> | ||
<r-part> | ||
<r-fetch .subscribe=${`{ notifications { appUpdated } }`}></r-fetch> | ||
<r-render | ||
.state=${( | ||
{ | ||
data: { | ||
notifications: { appUpdated } | ||
} | ||
}, | ||
setState: (s: NotificationState) => void | ||
) => html` | ||
<p>${appUpdated}</p> | ||
<button | ||
@click=${() => { | ||
setState({ | ||
data: { | ||
notifications: { | ||
appUpdated: Number(appUpdated) + Number(appUpdated) | ||
} | ||
} | ||
}); | ||
}} | ||
> | ||
Increment Subscriptions State x2 | ||
</button> | ||
(will be overriten when server emit new state) | ||
`} | ||
> | ||
</r-render> | ||
</r-part> | ||
`; | ||
} | ||
}) | ||
export class RHtmlViewComponent extends LitElement {} | ||
``` | ||
|
||
## Setup Graphql Client | ||
|
||
To set configuration on bundle time we need to get settings without `barrel` export, | ||
this way we can set configuration before Graphql module loads configuration | ||
Keep it in mind that this is the default configuration for GraphqlClient | ||
|
||
```typescript | ||
import { setConfig } from '@rhtml/graphql/settings'; | ||
|
||
setConfig({ | ||
config: { | ||
uri: 'https://countries.trevorblades.com/', | ||
pubsub: 'wss://pubsub.youvolio.com/subscriptions', | ||
async onRequest() { | ||
return new Headers(); | ||
} | ||
}, | ||
defaults: { | ||
error: e => { | ||
return html` | ||
<p style="color: black"> | ||
${e} | ||
</p> | ||
`; | ||
}, | ||
loading: () => { | ||
return html` | ||
<div style="text-align: center;"> | ||
<rx-loading palette="danger"></rx-loading> | ||
</div> | ||
`; | ||
} | ||
} | ||
}); | ||
|
||
import '@rhtml/graphql'; | ||
``` | ||
|
||
Later on you can use `r-fetch` component to specify `query`, `mutation`, `subscription` | ||
|
||
```html | ||
<r-part> | ||
<r-fetch .subscribe=${`{ notifications { appUpdated } }`}></r-fetch> | ||
<r-render .state=${({ data: { notifications: { appUpdated } } }, setState: (s: NotificationState) => void) => html` | ||
<p>${appUpdated}</p> | ||
<button | ||
@click=${() => { | ||
setState({ | ||
data: { | ||
notifications: { | ||
appUpdated: Number(appUpdated) + Number(appUpdated) | ||
} | ||
} | ||
}); | ||
}} | ||
> | ||
Increment Subscriptions State x2 | ||
</button> | ||
(will be overriten when server emit new state) | ||
`}> | ||
</r-render> | ||
</r-part> | ||
``` | ||
|
||
##### Dependency Injection | ||
|
||
``` | ||
npm i @rhtml/di | ||
``` | ||
|
||
```ts | ||
import '@abraham/reflection'; | ||
|
||
import { Inject, Injectable, InjectionToken } from '@rhtml/di'; | ||
import { Bootstrap, Component, Module } from '@rhtml/di/module'; | ||
|
||
type UserId = number; | ||
const UserId = new InjectionToken<UserId>(); | ||
|
||
const now = Date.now(); | ||
|
||
@Injectable() | ||
export class UserService { | ||
constructor(@Inject(UserId) public userId: number) { | ||
console.log('[UserService]', userId); | ||
} | ||
} | ||
|
||
@Component() | ||
class AppComponent { | ||
constructor(public userService: UserService) { | ||
console.log('[AppComponent] ', userService.userId); | ||
} | ||
|
||
OnInit() { | ||
console.log('[AppComponent] Init'); | ||
} | ||
|
||
OnDestroy() { | ||
console.log('[AppComponent] Destroy'); | ||
} | ||
} | ||
|
||
@Module({ | ||
providers: [ | ||
UserService, | ||
{ | ||
provide: UserId, | ||
useFactory: () => | ||
new Promise<number>(resolve => setTimeout(() => resolve(1234), 1000)) | ||
} | ||
], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule {} | ||
|
||
Bootstrap(AppModule).then(() => | ||
console.log('Started', `after ${Date.now() - now}`) | ||
); | ||
``` | ||
| Package | Description | | ||
| ---------------------------------- | ---------------------- | | ||
| [@rhtml/fastify](packages/fastify) | Fastify server package | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { readFile, readdir, writeFile } = require('fs'); | ||
const { promisify } = require('util'); | ||
async function readPackageJson(dir) { | ||
return JSON.parse(await promisify(readFile)(dir, { encoding: 'utf-8' })); | ||
} | ||
async function main() { | ||
const { version } = await readPackageJson('package.json'); | ||
const dirs = await promisify(readdir)('packages'); | ||
const packagesJsons = await Promise.all( | ||
dirs.map(async directory => { | ||
const path = `./packages/${directory}/package.json`; | ||
const file = await readPackageJson(path); | ||
return { | ||
file, | ||
path | ||
}; | ||
}) | ||
); | ||
const privatePackages = packagesJsons.map(json => json.file.name); | ||
const modified = packagesJsons.map(json => { | ||
json.file.dependencies = Object.entries(json.file.dependencies).reduce( | ||
(prev, [k]) => { | ||
if (privatePackages.includes(k)) { | ||
prev[k] = version; | ||
} | ||
return prev; | ||
}, | ||
json.file.dependencies | ||
); | ||
return json; | ||
}); | ||
await Promise.all( | ||
modified.map(({ file, path }) => | ||
promisify(writeFile)(path, JSON.stringify(file, null, 2), { | ||
encoding: 'utf-8' | ||
}) | ||
) | ||
); | ||
console.log(modified); | ||
} | ||
|
||
main(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.