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

Div #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"singleQuote": true
"singleQuote": true,
"endOfLine": "lf",
"printWidth": 120,
"tabWidth": 2,
"arrowParens": "always"
}
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const MyReactComponent = ({ title, myController }) => {
<h1>{title}</h1>
<p>{state}</p>
<p>
<NgTranslate
id={'TRANLATED_TEXT_ID'}
substitutions={myController.getValue()}
/>
<NgTranslate id={'TRANLATED_TEXT_ID'} substitutions={myController.getValue()} />
</p>
</>
);
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@tsconfig/node18": "1",
"@tsconfig/node18": "^2.0.0",
"@types/angular": "x",
"@types/angular-translate": "x",
"@types/jest": "^29.5.0",
Expand Down
5 changes: 1 addition & 4 deletions src/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ module.exports = {
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
env: {
Expand Down
34 changes: 6 additions & 28 deletions src/lib/ServiceProvider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
IHttpService,
IQService,
translate,
ILogService,
IFilterService,
} from 'angular';
import { IHttpService, IQService, translate, ILogService, IFilterService } from 'angular';

const globalServices = new Map<string, unknown>();

Expand All @@ -20,18 +14,9 @@ export function getService(
angularServiceName: '$translate',
ngOverride: { allowUnsafeAngularService: true }
): translate.ITranslateService;
export function getService(
angularServiceName: '$http',
ngOverride: { allowUnsafeAngularService: true }
): IHttpService;
export function getService(
angularServiceName: '$q',
ngOverride: { allowUnsafeAngularService: true }
): IQService;
export function getService(
angularServiceName: '$log',
ngOverride: { allowUnsafeAngularService: true }
): ILogService;
export function getService(angularServiceName: '$http', ngOverride: { allowUnsafeAngularService: true }): IHttpService;
export function getService(angularServiceName: '$q', ngOverride: { allowUnsafeAngularService: true }): IQService;
export function getService(angularServiceName: '$log', ngOverride: { allowUnsafeAngularService: true }): ILogService;
export function getService(
angularServiceName: '$filter',
ngOverride: { allowUnsafeAngularService: true }
Expand All @@ -41,10 +26,7 @@ export function getService(angularServiceName: '$http'): never;
export function getService(angularServiceName: '$q'): never;
export function getService(angularServiceName: '$log'): never;
export function getService(angularServiceName: '$filter'): never;
export function getService<T>(
name: ServiceName,
{ allowUnsafeAngularService = false } = {}
): T {
export function getService<T>(name: ServiceName, { allowUnsafeAngularService = false } = {}): T {
if (name.startsWith('$') && !allowUnsafeAngularService) {
throw Error(
// eslint-disable-next-line max-len
Expand All @@ -60,11 +42,7 @@ export function getService<T>(
}

function findService(name: string) {
if (
globalServices.has(name) ||
typeof window === 'undefined' ||
typeof window.angular === 'undefined'
) {
if (globalServices.has(name) || typeof window === 'undefined' || typeof window.angular === 'undefined') {
return globalServices.get(name);
}
return getAngularService(name);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/custom-hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export const useService = ((...params: Parameters<typeof getService>) => {
* @see NgTranslate for a better way to do this.
*/
export function useTranslate() {
const $translate = useMemo(
() => getAngularService<translate.ITranslateService>('$translate'),
[]
);
const $translate = useMemo(() => getAngularService<translate.ITranslateService>('$translate'), []);
return (id: string, subs?: unknown) => $translate.instant(id, subs);
}
5 changes: 1 addition & 4 deletions src/lib/jsx/NgTranslate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type Props = {
* @returns
*/
const NgTranslate = ({ id, substitutions }: Props) => {
const $translate = useMemo(
() => getAngularService<translate.ITranslateService>('$translate'),
[]
);
const $translate = useMemo(() => getAngularService<translate.ITranslateService>('$translate'), []);

return <>{$translate.instant(id, substitutions)}</>;
};
Expand Down
11 changes: 3 additions & 8 deletions src/lib/wrappers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import { IModule } from 'angular';
import * as React from 'react';
import { angularizeDirective, WrapperOptions } from './angularizeDirective';

export function angularize(
reactElement: React.ElementType,
{
name,
module,
...options
}: WrapperOptions & { name: string; module: IModule }
) {
type AngularizeOptions = WrapperOptions & WrapperOptions & { name: string; module: IModule };

export function angularize(reactElement: React.ElementType, { name, module, ...options }: AngularizeOptions) {
angularizeDirective(reactElement, name, module, options);
return module;
}