Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documention #254

Merged
merged 15 commits into from
Sep 24, 2022
Merged
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Build
*.js
*.map
*.d.ts
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"space-infix-ops": "error",
"new-cap": ["error", {"capIsNewExceptionPattern": "Mixin$"}],
"brace-style": ["error", "stroustrup", {"allowSingleLine": true}],
"operator-linebreak": ["error", "after", {"overrides": {"?": "before", ":": "before"}}],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

این مگه default نبود؟

"@typescript-eslint/explicit-function-return-type": "error",
"import/order": [
"error",
Expand Down
8 changes: 7 additions & 1 deletion .github/ISSUE_TEMPLATE/2-feature-request.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Feature Request'
description: Suggest a feature for Angular Framework
description: Suggest a feature for Alwatr packages

body:
- type: dropdown
Expand All @@ -12,6 +12,12 @@ body:
- logger
- router
- signal
- token
- nano-server
- element
- i18n
- math
- font
- Don't known / other
multiple: true
validations:
Expand Down
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Telegram group of Alwatr developers
url: 'https://t.me/AlwatrWG'
about: Communication with developers
4 changes: 3 additions & 1 deletion packages/core/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function sayHello(name: string) {

### Debug Mode

Many of the methods in the logger are no-ops when the debug mode is off.
Many of the methods in the logger are no-ops when the debug mode is off in the browser.
Please remember to **reload** the window after changing the debug mode.

- Debugging all scopes
Expand All @@ -37,6 +37,8 @@ Please remember to **reload** the window after changing the debug mode.
window.localStorage?.setItem('ALWATR_DEBUG', '*alwatr*');
```

> Make sure the [log level](https://developer.chrome.com/docs/devtools/console/log/#browser) in set correctly.

## API

### `createLogger(scope: string, color: string, force = boolean)`
Expand Down
32 changes: 16 additions & 16 deletions packages/core/logger/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ alwatrRegisteredList.push({
* Color list storage for logger.
*/
let colorIndex = 0;
const colorList = isBrowser ?
[
const colorList = isBrowser
? [
'#35b997',
'#f05561',
'#ee224a',
Expand All @@ -35,8 +35,8 @@ const colorList = isBrowser ?
'#1da2dc',
'#f05123',
'#ee2524',
] :
['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted
]
: ['0;36', '0;35', '0;34', '0;33', '0;32']; // red and white omitted

const getNextColor = (): string => {
const color = colorList[colorIndex];
Expand All @@ -47,9 +47,9 @@ const getNextColor = (): string => {
return color;
};

const debugString = isBrowser ?
globalThis.localStorage?.getItem('ALWATR_DEBUG')?.trim() :
globalThis.process?.env?.ALWATR_DEBUG?.trim();
const debugString = isBrowser
? globalThis.localStorage?.getItem('ALWATR_DEBUG')?.trim()
: globalThis.process?.env?.ALWATR_DEBUG?.trim();

const getDebugState = (scope: string): boolean => {
if (debugString == null && isBrowser === false && globalThis.process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -128,13 +128,13 @@ export const createLogger = (
color,
scope,

accident: isBrowser ?
console.warn.bind(console, '%c%s%c.%s "%s" => Accident: "%s" (%s)!', styleScope, scope, style.reset) :
console.warn.bind(console, `${styleScope}⚠️ %s\x1b[33m.%s "%s" =>${style.reset}`, scope),
accident: isBrowser
? console.warn.bind(console, '%c%s%c.%s "%s" => Accident: "%s" (%s)!', styleScope, scope, style.reset)
: console.warn.bind(console, `${styleScope}⚠️ %s\x1b[33m.%s "%s" =>${style.reset}`, scope),

error: isBrowser ?
console.error.bind(console, '%c%s%c.%s "%s" =>', styleScope, scope, style.reset) :
console.error.bind(console, `${styleScope}❌ %s\x1b[31m.%s "%s" =>\x1b[0;2m`, scope),
error: isBrowser
? console.error.bind(console, '%c%s%c.%s "%s" =>', styleScope, scope, style.reset)
: console.error.bind(console, `${styleScope}❌ %s\x1b[31m.%s "%s" =>\x1b[0;2m`, scope),
};

if (!debug) {
Expand All @@ -161,9 +161,9 @@ export const createLogger = (

logMethodFull: console.debug.bind(console, keySection + '.%s(%o); // %o', styleScope, scope, style.reset),

incident: isBrowser ?
console.trace.bind(console, '%c%s%c.%s() => Incident: "%s" (%s)!', styleScope, scope, style.reset) :
console.log.bind(console, `${styleScope}🔸 %s${style.reset}.%s() => Incident: "%s" (%s)!\x1b[0;2m`, scope),
incident: isBrowser
? console.trace.bind(console, '%c%s%c.%s() => Incident: "%s" (%s)!', styleScope, scope, style.reset)
: console.log.bind(console, `${styleScope}🔸 %s${style.reset}.%s() => Incident: "%s" (%s)!\x1b[0;2m`, scope),

logOther: console.debug.bind(console, keySection, styleScope, scope, style.reset),
};
Expand Down
8 changes: 4 additions & 4 deletions packages/core/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ export class AlwatrConnection {
catch {
this._logger.accident('responseData', 'data_stringify_failed', 'JSON.stringify(data) failed!');
return this.reply(
content.ok === false ?
{
content.ok === false
? {
ok: false,
statusCode: content.statusCode,
errorCode: content.errorCode,
} :
{
}
: {
ok: false,
statusCode: 500,
errorCode: 'data_stringify_failed',
Expand Down
2 changes: 2 additions & 0 deletions packages/core/signal/src/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class SignalInterface<SignalName extends keyof AlwatrSignals> {
): ListenerInterface<SignalName> {
this._logger.logMethodArgs('setProvider', {options});
const listener = _setSignalProvider(this._signal, this._requestSignal, signalProvider, options);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

این چیه؟

return new ListenerInterface(this._requestSignal, listener);
}

Expand Down Expand Up @@ -235,6 +236,7 @@ export class SignalInterface<SignalName extends keyof AlwatrSignals> {
): ListenerInterface<SignalName> {
this._logger.logMethodArgs('addListener', {options});
const listener = _addSignalListener(this._signal, listenerCallback, options);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new ListenerInterface(this._signal, listener);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/storage/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import exitHook from 'exit-hook';

import {readJsonFile, writeJsonFile} from './util.js';

import type {DocumentObject, DocumentListStorage, AlwatrStorageConfig} from './type';
import type {DocumentObject, DocumentListStorage, AlwatrStorageConfig} from './type.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

تو import type که .js لازم نداره!


export {DocumentObject, DocumentListStorage, AlwatrStorageConfig as Config};

Expand Down