repo_name stringlengths 1 62 | dataset stringclasses 1
value | lang stringclasses 11
values | pr_id int64 1 20.1k | owner stringlengths 2 34 | reviewer stringlengths 2 39 | diff_hunk stringlengths 15 262k | code_review_comment stringlengths 1 99.6k |
|---|---|---|---|---|---|---|---|
ngxtension-platform | github_2023 | others | 122 | ngxtension | eneajaho | @@ -84,31 +86,46 @@ setTimeout(() => {
// You can copy the above example inside an Angular constructor and see the result in the console.
```
-The console log will be:
+This will _throw an error_ because the operation pipeline used will produce an observable that will **not have a sync value** because they emit lat... | ```suggestion
startWith(0) // π change the starting value (emits synchronously)
``` |
ngxtension-platform | github_2023 | others | 135 | ngxtension | nartc | @@ -0,0 +1,117 @@
+---
+title: signalSlice
+description: ngxtension/signalSlice
+---
+
+`signalSlice` is loosely inspired by the `createSlice` API from Redux Toolkit. The general idea is that it allows you to declaratively create a "slice" of state. This state will be available as a **readonly** signal.
+
+The key moti... | nit: this should probably be assigned to something else then use that in the `sources` array below? |
ngxtension-platform | github_2023 | others | 135 | ngxtension | nartc | @@ -0,0 +1,117 @@
+---
+title: signalSlice
+description: ngxtension/signalSlice
+---
+
+`signalSlice` is loosely inspired by the `createSlice` API from Redux Toolkit. The general idea is that it allows you to declaratively create a "slice" of state. This state will be available as a **readonly** signal.
+
+The key moti... | ```suggestion
When you supply a `reducer`, it will automatically create an `action` that you can call. Reducers can be created like this:
``` |
ngxtension-platform | github_2023 | others | 135 | ngxtension | nartc | @@ -0,0 +1,117 @@
+---
+title: signalSlice
+description: ngxtension/signalSlice
+---
+
+`signalSlice` is loosely inspired by the `createSlice` API from Redux Toolkit. The general idea is that it allows you to declaratively create a "slice" of state. This state will be available as a **readonly** signal.
+
+The key moti... | suggestion: I'd love to mention a reducer without a payload can simply be called without parameters |
ngxtension-platform | github_2023 | typescript | 117 | ngxtension | ajitzero | @@ -0,0 +1,62 @@
+import {
+ Directive,
+ ElementRef,
+ EventEmitter,
+ inject,
+ Injectable,
+ NgZone,
+ Output,
+} from '@angular/core';
+
+import type { OnInit } from '@angular/core';
+import { injectDestroy } from 'ngxtension/inject-destroy';
+import { fromEvent, Subject, takeUntil } from 'rxjs';
+
+/*
+ * This ser... | ```suggestion
.pipe(
map(event => this.elementRef.nativeElement.contains(
event.target
)),
filter(isClickedInside => !isClickedInside),
takeUntil(this.destroy$),
)
.subscribe((event: Event) => {
this.ngZone.run(() => this.clickOutside.emit(event));
```
Suggestion: I'm ... |
ngxtension-platform | github_2023 | typescript | 117 | ngxtension | ajitzero | @@ -0,0 +1,62 @@
+import {
+ Directive,
+ ElementRef,
+ EventEmitter,
+ inject,
+ Injectable,
+ NgZone,
+ Output,
+} from '@angular/core';
+
+import type { OnInit } from '@angular/core';
+import { injectDestroy } from 'ngxtension/inject-destroy';
+import { fromEvent, Subject, takeUntil } from 'rxjs';
+
+/*
+ * This ser... | nit: Can you please use the inject function here instead? This is purely to be consistent with the rest of the files, including this one, where below we can see inject being used.
Can be skipped if it's too much trouble. |
ngxtension-platform | github_2023 | typescript | 117 | ngxtension | nartc | @@ -0,0 +1,62 @@
+import {
+ Directive,
+ ElementRef,
+ EventEmitter,
+ inject,
+ Injectable,
+ NgZone,
+ Output,
+} from '@angular/core';
+
+import type { OnInit } from '@angular/core';
+import { injectDestroy } from 'ngxtension/inject-destroy';
+import { fromEvent, Subject, takeUntil } from 'rxjs';
+
+/*
+ * This ser... | nit: I would remove `Directive` from the name of the directive, just `ClickOutside` is enough |
ngxtension-platform | github_2023 | typescript | 117 | ngxtension | nartc | @@ -0,0 +1,62 @@
+import {
+ Directive,
+ ElementRef,
+ EventEmitter,
+ inject,
+ Injectable,
+ NgZone,
+ Output,
+} from '@angular/core';
+
+import type { OnInit } from '@angular/core';
+import { injectDestroy } from 'ngxtension/inject-destroy';
+import { fromEvent, Subject, takeUntil } from 'rxjs';
+
+/*
+ * This ser... | suggestion: this can easily be a CIF instead of a full-blown class, especially we don't even expose this as a public API for `click-outside`
```ts
const [injectDocumentClick] = createInjectionToken(() => {
const click$ = new Subject<MouseEvent>();
const [ngZone, document] = [inject(NgZone), inject(DOCUMEN... |
ngxtension-platform | github_2023 | typescript | 117 | ngxtension | nartc | @@ -0,0 +1,62 @@
+import {
+ Directive,
+ ElementRef,
+ EventEmitter,
+ inject,
+ Injectable,
+ NgZone,
+ Output,
+} from '@angular/core';
+
+import type { OnInit } from '@angular/core';
+import { injectDestroy } from 'ngxtension/inject-destroy';
+import { fromEvent, Subject, takeUntil } from 'rxjs';
+
+/*
+ * This ser... | question: why does this have to be in `ngOnInit`? |
ngxtension-platform | github_2023 | typescript | 113 | ngxtension | tomalaforge | @@ -0,0 +1,58 @@
+import { from, of, toArray } from 'rxjs';
+import { filterUndefined, mapSkipUndefined } from './map-skip-undefined';
+
+describe(filterUndefined.name, () => {
+ it('given an observable of null, undefined, 42, filter out the undefined, emit null and 42', (done) => {
+ const in$ = of(null, undefined, 4... | simple questio: why did you go with 'toArray' instead of observer-spy? |
ngxtension-platform | github_2023 | others | 101 | ngxtension | ajitzero | @@ -0,0 +1,29 @@
+---
+title: mapFilter
+description: An RxJS operator that allow to apply a trasform function to each value of the observable in (same as map), but with the ability to skip (filter out) some values if the function explict return undefined or simply doesn't return anything for same code-path (implict re... | ```suggestion
description: An RxJS operator that allows applying a transform function to each value of the observable in (same as map), but with the ability to skip (filter out) some values if the function explicit return undefined or simply doesn't return anything for same code-path (implicit return undefined).
```
... |
ngxtension-platform | github_2023 | others | 101 | ngxtension | ajitzero | @@ -0,0 +1,29 @@
+---
+title: mapFilter
+description: An RxJS operator that allow to apply a trasform function to each value of the observable in (same as map), but with the ability to skip (filter out) some values if the function explict return undefined or simply doesn't return anything for same code-path (implict re... | ```suggestion
You can use it as a normal map operator, but with the ability to skip some values: returning undefined (explicit or implicit).
``` |
ngxtension-platform | github_2023 | others | 101 | ngxtension | ajitzero | @@ -0,0 +1,33 @@
+{
+ "name": "ngxtension/mapfilter", | nit: Not sure about the naming scheme but should the file be `ngxtension/map-filter` instead (hyphen in middle?) |
ngxtension-platform | github_2023 | others | 101 | ngxtension | ajitzero | @@ -0,0 +1,29 @@
+---
+title: mapFilter
+sdescription: An RxJS operator that allows applying a transform function to each value of the observable in (same as map), but with the ability to skip (filter out) some values if the function explicit return undefined or simply doesn't return anything for same code-path (implic... | ```suggestion
description: An RxJS operator that allows applying a transform function to each value of the observable in (same as map), but with the ability to skip (filter out) some values if the function explicitly returns undefined or simply doesn't return anything for same code-path (implicit return undefined).
`... |
ngxtension-platform | github_2023 | typescript | 101 | ngxtension | tomalaforge | @@ -0,0 +1,11 @@
+import { type Observable } from 'rxjs';
+import { filter, map } from 'rxjs/operators';
+
+export function mapFilter<T, R>(fnTrasformSkipUndefined: (value: T) => R) {
+ return function (source: Observable<T>): Observable<Exclude<R, undefined>> {
+ return source.pipe(
+ map(fnTrasformSkipUndefined),
... | you can use `filterNil()`here, this way I don't think you need to cast you observable at the end. |
ngxtension-platform | github_2023 | typescript | 101 | ngxtension | tomalaforge | @@ -0,0 +1,57 @@
+import { from } from 'rxjs';
+import { mapFilter } from './mapfilter';
+
+describe(mapFilter.name, () => {
+ it('given an observable >1-42-3| and a mapping function that double ONLY the odds value, then result is an observable of >"2"--"6"-| the intial even value (42) is not mapped and so filtered out... | I don't get your test. Why are you not simply testing the returned value ? It makes your test very hard to understand.
We could add observableSpy to eaiser test observable. What do you thing @nartc ?
And out$ is asynchronous so the subscribe is executed after the expect, that's why the test is failing |
ngxtension-platform | github_2023 | others | 115 | ngxtension | nartc | @@ -0,0 +1,117 @@
+---
+title: injectLazy
+description: ngxtension/inject-lazy
+---
+
+`injectLazy` is a helper function that allows us to lazily load a service or any kind of Angular provider.
+
+Lazy loading services is useful when we want to shrink the bundle size by loading services only when they are needed.
+
+``... | nit: `injectLazy` instead of `lazyService` here? |
ngxtension-platform | github_2023 | typescript | 115 | ngxtension | nartc | @@ -0,0 +1,35 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | question: what is `lazyService` for? |
ngxtension-platform | github_2023 | typescript | 110 | ngxtension | nartc | @@ -0,0 +1,20 @@
+import { DOCUMENT } from '@angular/common';
+import { assertInInjectionContext, inject, type Injector } from '@angular/core';
+import { fromEvent, map, merge, shareReplay } from 'rxjs';
+
+export function injectActiveElement(injector?: Injector) {
+ injector ?? assertInInjectionContext(injectActiveEle... | suggestion: use `assertInjector` for this. You can look at the other `inject***` to see the usages. |
ngxtension-platform | github_2023 | typescript | 110 | ngxtension | nartc | @@ -0,0 +1,20 @@
+import { DOCUMENT } from '@angular/common';
+import { assertInInjectionContext, inject, type Injector } from '@angular/core';
+import { fromEvent, map, merge, shareReplay } from 'rxjs';
+
+export function injectActiveElement(injector?: Injector) {
+ injector ?? assertInInjectionContext(injectActiveEle... | question: would it make sense to allow the consumers to configure the event options? |
ngxtension-platform | github_2023 | others | 110 | ngxtension | eneajaho | @@ -0,0 +1,60 @@
+---
+title: injectActiveElement
+description: An Angular utility to create an Observable that emits active element from the document.
+---
+
+## Import
+
+```ts
+import { injectActiveElement } from 'ngxtension/active-element';
+```
+
+## Usage
+
+### Basic
+
+Create an Observable that emits when the a... | ```suggestion
const activeElement$ = injectActiveElement(this.injector);
``` |
ngxtension-platform | github_2023 | typescript | 110 | ngxtension | nartc | @@ -0,0 +1,22 @@
+import { DOCUMENT } from '@angular/common';
+import { inject, Injector } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { fromEvent, map, merge, shareReplay } from 'rxjs';
+
+export function injectActiveElement(injector?: Injector) {
+ return assertInjector... | ```suggestion
const doc = inject(DOCUMENT);
``` |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | LcsGa | @@ -0,0 +1,39 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | ```suggestion
```
This `catch` won't have any effect. The `defer` function will take care of it and emit the error for you in the resulting observable. |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | LcsGa | @@ -0,0 +1,39 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | I was wondering if adding a `shareReplay` could be a good idea, to avoid "refetching" the service more than once?
Or maybe would it be too hidden? |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | JeanMeche | @@ -0,0 +1,39 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | We might want to have `ProviderToken<T>` instead of `Type<T>` since a ProviderToken could come with its factory. wdyt ? |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | JeanMeche | @@ -0,0 +1,39 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | While this function works fine, it kind of bothers me that we can't mock the loaded instance.
See http://riegler.fr/blog/2023-09-30-lazy-loading-mockable For an implementation that provides suck mocking abilities ! |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | JeanMeche | @@ -0,0 +1,39 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | In which case is this necessary ? |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | JeanMeche | @@ -0,0 +1,39 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | If the service uses `DestroyRef.onDestroy()` it will never be called.
Even if `injector` is a `NodeInjector`, this works only with `providedIn: root`. So it's the root injector that will provide the `DestroyRef` (and thus never call `OnDestroy`.
The solution would be to create an `EnvironmentInjector` that pro... |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | JeanMeche | @@ -0,0 +1,174 @@
+import { AsyncPipe } from '@angular/common';
+import {
+ ChangeDetectorRef,
+ Component,
+ inject,
+ Injectable,
+ Injector,
+ OnInit,
+ Type,
+} from '@angular/core';
+import {
+ ComponentFixture,
+ fakeAsync,
+ TestBed,
+ tick,
+} from '@angular/core/testing';
+import { catchError, of, switchMap } ... | This tests succeeds even without the `runInInjectionContext` |
ngxtension-platform | github_2023 | typescript | 80 | ngxtension | JeanMeche | @@ -0,0 +1,39 @@
+import { Injector, Type, runInInjectionContext } from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, defer } from 'rxjs';
+
+/**
+ * Loads a service lazily. The service is loaded when the observable is subscribed to.
+ *
+ * @param loader A functio... | This function only currently only works with providedIn:'root' services. |
ngxtension-platform | github_2023 | typescript | 109 | ngxtension | nartc | @@ -0,0 +1,61 @@
+import {
+ DestroyRef,
+ ElementRef,
+ inject,
+ Injector,
+ runInInjectionContext,
+} from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { injectDestroy } from 'ngxtension/inject-destroy';
+import { IsInViewportService } from './is-in-viewport.service';
+
+exp... | suggestion: one trick I use for optional option object is to destructure the object and give it a default value of `{}`.
```suggestion
export const injectIsIntersecting = ({ element, injector }: InjectIsIntersectingOptions = {}) => {
``` |
ngxtension-platform | github_2023 | others | 104 | ngxtension | nartc | @@ -116,7 +128,49 @@ export const [injectService, provideService] = createInjectionToken(serviceFacto
Note that if `token` is passed in and `isRoot: true`, `createInjectionToken` will throw an error.
-### Injector
+### `CreateNooptInjectionToken` | ```suggestion
### `createNooptInjectionToken`
``` |
ngxtension-platform | github_2023 | others | 104 | ngxtension | nartc | @@ -116,7 +128,49 @@ export const [injectService, provideService] = createInjectionToken(serviceFacto
Note that if `token` is passed in and `isRoot: true`, `createInjectionToken` will throw an error.
-### Injector
+### `CreateNooptInjectionToken`
+
+As the name suggested, `createNooptInjectionToken` is the same as... | ```suggestion
Note **true** inside `createNoopInjectionToken<number, true>` and in `multi: true`. This is to help TypeScript to return the correct type for `injectFn` and `provideFn`
``` |
ngxtension-platform | github_2023 | others | 104 | ngxtension | nartc | @@ -116,7 +128,49 @@ export const [injectService, provideService] = createInjectionToken(serviceFacto
Note that if `token` is passed in and `isRoot: true`, `createInjectionToken` will throw an error.
-### Injector
+### `CreateNooptInjectionToken`
+
+As the name suggested, `createNooptInjectionToken` is the same as... | ```suggestion
`createInjectionToken` and `createNoopInjectionToken` returns a `provideFn` which is a function that accepts either a value or a **factory function** that returns the value.
In the case where the value of the token is a `Function` (i.e: `NG_VALIDATORS` is a multi token whose values are functions), `pr... |
ngxtension-platform | github_2023 | others | 104 | ngxtension | nartc | @@ -116,7 +128,49 @@ export const [injectService, provideService] = createInjectionToken(serviceFacto
Note that if `token` is passed in and `isRoot: true`, `createInjectionToken` will throw an error.
-### Injector
+### `CreateNooptInjectionToken`
+
+As the name suggested, `createNooptInjectionToken` is the same as... | ```suggestion
const [injectFn, provideFn] = createInjectionToken(() => {
// this token returns Function as value
return () => 1;
});
``` |
ngxtension-platform | github_2023 | typescript | 81 | ngxtension | nartc | @@ -0,0 +1,73 @@
+/* eslint-disable @typescript-eslint/ban-types */
+import {
+ effect,
+ ElementRef,
+ HostBinding,
+ inject,
+ Injector,
+ Renderer2,
+ RendererStyleFlags2,
+ runInInjectionContext,
+ Signal,
+ WritableSignal,
+} from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+
+/*... | issue: the `effect` should be inside of `runInInjectionContext`. If not, then the `injector` needs to be passed into the `effect` 2nd argument.
```ts
return runInInjectContext(injector, () => {
/* logic */
effect(() => {
/* more effect logic */
});
return signal;
})
```
Also... |
ngxtension-platform | github_2023 | others | 81 | ngxtension | nartc | @@ -0,0 +1,46 @@
+---
+title: hostBinding
+description: ngxtension/host-binding
+---
+
+`hostBinding` is a function that returns either a _writable_ or _readonly_ signal and binds the value held in that signal to the host property passed as the first argument like `@HostBinding` would do.
+
+```ts
+import { hostBinding... | question: can we add a usage in combination with Input? There will be 2 cases:
- Observable Input like people do today with setter Inputs
```ts
export class MyComponent {
#color = new BehaviorSubject('red');
@Input() set color(color: 'red' | 'blue') {
this.#color.next(color);
}
// ... |
ngxtension-platform | github_2023 | typescript | 81 | ngxtension | nartc | @@ -0,0 +1,75 @@
+/* eslint-disable @typescript-eslint/ban-types */
+import {
+ effect,
+ ElementRef,
+ HostBinding,
+ inject,
+ Injector,
+ Renderer2,
+ RendererStyleFlags2,
+ runInInjectionContext,
+ Signal,
+ WritableSignal,
+} from '@angular/core';
+import { assertInjector } from 'ngxtension/assert-injector';
+
+/*... | nit: I think this is trying to be too smart here. Does this have to be recreated every time the effect triggers? I would rather create the object outside of the `effect` or just good ol' if/elseif instead. |
ngxtension-platform | github_2023 | typescript | 74 | ngxtension | nartc | @@ -0,0 +1,9 @@
+import { map } from 'rxjs';
+
+export const reduceArray = <T, R>( | suggestion: for `reduce`, it's better to make `R = T` so if the consumers don't pass in initial value, then the return type is the type of the item in the Array. I.e: `nums.reduce((a, c) => a + c)`
```suggestion
export const reduceArray = <T, R = T>(
``` |
ngxtension-platform | github_2023 | typescript | 74 | ngxtension | nartc | @@ -0,0 +1,33 @@
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
+
+export function reduceArray<T>(
+ reduceFn: (acc: T, item: T, index: number) => T
+): (source: Observable<T[]>) => Observable<T>;
+
+export function reduceArray<T, R = T>(
+ reduceFn: (acc: R, item: T, index: number) => R,
+ ... | suggestion: `initialValue` here doesn't have to be optional
```suggestion
initialValue: R
``` |
ngxtension-platform | github_2023 | typescript | 74 | ngxtension | nartc | @@ -0,0 +1,63 @@
+import { of } from 'rxjs';
+import { reduceArray } from './reduce-array';
+
+describe(reduceArray.name, () => {
+ const input$ = of([1, 2, 3]);
+ const emptyArray$ = of([]);
+
+ it('sums elements, result is 6', (done) => {
+ const result = input$.pipe(reduceArray((acc, n) => acc + n, 0));
+
+ result... | nit: this test looks a bit weird to me. Here's what I'd do
```suggestion
it('empty array observable, no initial value, result is undefined', (done) => {
let count = 0;
const result = emptyArray$.pipe(
reduceArray((_, n) => {
count += 1;
return n;
})
);
result.subscribe((r) => {
... |
ngxtension-platform | github_2023 | typescript | 74 | ngxtension | nartc | @@ -0,0 +1,33 @@
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
+
+export function reduceArray<T>(
+ reduceFn: (acc: T, item: T, index: number) => T
+): (source: Observable<T[]>) => Observable<T>;
+
+export function reduceArray<T, R = T>(
+ reduceFn: (acc: R, item: T, index: number) => R,
+ ... | nit: unnecessary else |
ngxtension-platform | github_2023 | typescript | 74 | ngxtension | nartc | @@ -0,0 +1,33 @@
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
+
+export function reduceArray<T>(
+ reduceFn: (acc: T, item: T, index: number) => T
+): (source: Observable<T[]>) => Observable<T>;
+
+export function reduceArray<T, R = T>(
+ reduceFn: (acc: R, item: T, index: number) => R,
+ ... | nit/suggestion: the `T` for the implementation with overloads is redundant. Clean them all up with `any`. However for this case, that might be too many `any`. So here's my suggestion:
```ts
type AnyArray = Array<any>;
type ReduceParameters = Parameters<AnyArray['reduce']>;
export function reduceArray<T>(
redu... |
ngxtension-platform | github_2023 | typescript | 92 | ngxtension | tomalaforge | @@ -1,9 +1,9 @@
import {
AbstractControl,
- AsyncValidatorFn,
FormControl,
- ValidatorFn,
Validators,
+ type AsyncValidatorFn,
+ type ValidatorFn, | nitpick: this refacto should have been done in a separate PR |
ngxtension-platform | github_2023 | typescript | 92 | ngxtension | tomalaforge | @@ -0,0 +1,2 @@
+export * from './drag';
+export * from './zoneless-gesture'; | personal opinion: I always prefer to explicitly export what I want to export
export {xxx} from '....'
|
ngxtension-platform | github_2023 | others | 78 | ngxtension | tomalaforge | @@ -0,0 +1,20 @@
+{
+ "migrations": [
+ {
+ "cli": "nx",
+ "version": "16.9.0-beta.1",
+ "description": "Replace imports of Module Federation utils frm @nx/devkit to @nx/webpack",
+ "implementation": "./src/migrations/update-16-9-0/migrate-mf-util-usage",
+ "package": "@nx/devkit",
+ "name": "update-16-9-0... | This file doesn't need to be commited, doest it ? |
ngxtension-platform | github_2023 | typescript | 75 | ngxtension | tomalaforge | @@ -0,0 +1,81 @@
+import {
+ inject,
+ InjectionToken,
+ LOCALE_ID,
+ Pipe,
+ PipeTransform,
+ Provider,
+} from '@angular/core';
+
+type DisplayNamesOptions = Omit<Intl.DisplayNamesOptions, 'type'>;
+
+/**
+ * @internal
+ */
+const defaultOptions: DisplayNamesOptions = {
+ style: 'short',
+ localeMatcher: 'lookup',
+ ... | question: why can we not change the style of DisplayName with pipe argument as well, to make it more specific to each pipe and not having to override the provider ? |
ngxtension-platform | github_2023 | typescript | 75 | ngxtension | nartc | @@ -0,0 +1,84 @@
+import {
+ inject,
+ InjectionToken,
+ LOCALE_ID,
+ Pipe,
+ PipeTransform,
+ Provider,
+} from '@angular/core';
+
+type DisplayNamesOptions = Omit<Intl.DisplayNamesOptions, 'type'>;
+
+/**
+ * @internal
+ */
+const defaultOptions: DisplayNamesOptions = {
+ style: 'short',
+ localeMatcher: 'lookup',
+ ... | nit: let's log the error so folks know what's going on? |
ngxtension-platform | github_2023 | typescript | 75 | ngxtension | nartc | @@ -0,0 +1,84 @@
+import {
+ inject,
+ InjectionToken,
+ LOCALE_ID,
+ Pipe,
+ PipeTransform,
+ Provider,
+} from '@angular/core';
+
+type DisplayNamesOptions = Omit<Intl.DisplayNamesOptions, 'type'>;
+
+/**
+ * @internal
+ */
+const defaultOptions: DisplayNamesOptions = {
+ style: 'short',
+ localeMatcher: 'lookup',
+ ... | suggestion/discussion: The creation of the `InjectionToken` is straight-forward but I think we can make this more consistent with the rest of the library by using `createInjectionToken` utility?
This can be rewritten with the following:
```ts
const [injectFn, provideFn] = createInjectionToken(() => defaultOption... |
ngxtension-platform | github_2023 | others | 71 | ngxtension | eneajaho | @@ -24,12 +26,34 @@ import { NavigationEnd } from '@angular/router';
template: '<p>Example Component</p>',
})
export class ExampleComponent {
- navigationEnd$ = injectNavigationEnd();
+ source$ = injectNavigationEnd();
constructor() {
- navigationEnd$.subscribe((event: NavigationEnd) => {
- // This code will r... | Shouldn't this be inside ngOnInit to show it correctly? |
ngxtension-platform | github_2023 | others | 66 | ngxtension | nartc | @@ -0,0 +1,22 @@
+---
+title: filter nil RxJs operator
+description: ngxtension/filter-array | nit: wrong description>? |
ngxtension-platform | github_2023 | typescript | 66 | ngxtension | nartc | @@ -0,0 +1,5 @@
+import { map, pipe } from 'rxjs';
+
+export const filterArray = <T>(filterFn: (item: T) => boolean) => {
+ return pipe(map((array: T[]) => array.filter((item) => filterFn(item)))); | suggestion: I'm pretty sure `pipe()` isn't needed. |
ngxtension-platform | github_2023 | typescript | 66 | ngxtension | nartc | @@ -0,0 +1,9 @@
+import { filter, pipe } from 'rxjs';
+
+export const filterNil = <T>() =>
+ pipe( | suggestion: `pipe()` isn't needed |
ngxtension-platform | github_2023 | typescript | 66 | ngxtension | nartc | @@ -0,0 +1,5 @@
+import { map, pipe } from 'rxjs';
+
+export const mapArray = <T, R>(mapFn: (item: T) => R) => {
+ return pipe(map((array: T[]) => array.map((item) => mapFn(item)))); | suggestion: `pipe()` isn't needed |
ngxtension-platform | github_2023 | others | 66 | ngxtension | nartc | @@ -39,7 +39,11 @@
"lintFilePatterns": [
"libs/ngxtension/**/*.ts",
"libs/ngxtension/**/*.html",
- "libs/ngxtension/package.json"
+ "libs/ngxtension/package.json",
+ "libs/ngxtension/filter-array/**/*.ts",
+ "libs/ngxtension/filter-array/**/*.html",
+ "libs/ngxtension/filter-nil/**/... | comment: remove these |
ngxtension-platform | github_2023 | typescript | 59 | ngxtension | nartc | @@ -0,0 +1,42 @@
+//INSPIRED BY https://medium.com/ngconf/make-trackby-easy-to-use-a3dd5f1f733b
+import { NgForOf } from '@angular/common';
+import {
+ Directive,
+ Input,
+ Provider,
+ inject,
+ type NgIterable,
+} from '@angular/core';
+
+@Directive({
+ selector: '[ngForTrackById]',
+ standalone: true,
+})
+export cl... | nit: what do you think of dropping `Directive` off of the name? Like `NgFor` and `NgIf`, they don't have the `Directive` appended. |
ngxtension-platform | github_2023 | typescript | 59 | ngxtension | nartc | @@ -0,0 +1,42 @@
+//INSPIRED BY https://medium.com/ngconf/make-trackby-easy-to-use-a3dd5f1f733b
+import { NgForOf } from '@angular/common';
+import {
+ Directive,
+ Input,
+ Provider,
+ inject,
+ type NgIterable,
+} from '@angular/core';
+
+@Directive({
+ selector: '[ngForTrackById]',
+ standalone: true,
+})
+export cl... | nit: what do you think of dropping Directive off of the name? Like NgFor and NgIf, they don't have the Directive appended. |
ngxtension-platform | github_2023 | typescript | 59 | ngxtension | nartc | @@ -0,0 +1,42 @@
+//INSPIRED BY https://medium.com/ngconf/make-trackby-easy-to-use-a3dd5f1f733b
+import { NgForOf } from '@angular/common';
+import {
+ Directive,
+ Input,
+ Provider,
+ inject,
+ type NgIterable,
+} from '@angular/core';
+
+@Directive({
+ selector: '[ngForTrackById]',
+ standalone: true,
+})
+export cl... | suggestion: maybe we can use `{required: true}` here |
ngxtension-platform | github_2023 | typescript | 59 | ngxtension | nartc | @@ -0,0 +1,42 @@
+//INSPIRED BY https://medium.com/ngconf/make-trackby-easy-to-use-a3dd5f1f733b
+import { NgForOf } from '@angular/common';
+import {
+ Directive,
+ Input,
+ Provider,
+ inject,
+ type NgIterable,
+} from '@angular/core';
+
+@Directive({
+ selector: '[ngForTrackById]',
+ standalone: true,
+})
+export cl... | comment: maybe with `{required: true}`, we don't need to check here or throw error instead of early return |
ngxtension-platform | github_2023 | typescript | 59 | ngxtension | nartc | @@ -0,0 +1,42 @@
+//INSPIRED BY https://medium.com/ngconf/make-trackby-easy-to-use-a3dd5f1f733b
+import { NgForOf } from '@angular/common';
+import {
+ Directive,
+ Input,
+ Provider,
+ inject,
+ type NgIterable,
+} from '@angular/core';
+
+@Directive({
+ selector: '[ngForTrackById]',
+ standalone: true,
+})
+export cl... | suggestion: For this, I'd use `TRACK_BY_DIRECTIVES` instead |
ngxtension-platform | github_2023 | typescript | 52 | ngxtension | nartc | @@ -0,0 +1,22 @@
+import { Injector, inject, runInInjectionContext } from '@angular/core';
+import { Event, NavigationEnd, Router } from '@angular/router';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable } from 'rxjs';
+import { filter } from 'rxjs/operators';
+
+/**
+ * Creates an Ob... | ```suggestion
return inject(Router).events.pipe(
``` |
ngxtension-platform | github_2023 | others | 52 | ngxtension | nartc | @@ -0,0 +1,35 @@
+---
+title: navigationEnd
+description: ngxtension/navigation-end
+---
+
+The `navigationEnd` function is a utility for creating an Observable that emits when a navigation ends. It might be used to perform tasks after a route navigation has been completed. | ```suggestion
The `navigationEnd` function is a utility for creating an `Observable` that emits when a navigation ends. It might perform tasks after a route navigation has been completed.
``` |
ngxtension-platform | github_2023 | typescript | 52 | ngxtension | nartc | @@ -0,0 +1,52 @@
+import { Component } from '@angular/core';
+import {
+ ComponentFixture,
+ TestBed,
+ fakeAsync,
+ tick,
+} from '@angular/core/testing';
+import { NavigationEnd, Router } from '@angular/router';
+import { delay, of } from 'rxjs';
+import { navigationEnd } from './navigation-end';
+
+describe(navigati... | nit: maybe change the test name? |
ngxtension-platform | github_2023 | typescript | 52 | ngxtension | nartc | @@ -0,0 +1,22 @@
+import { Injector, inject, runInInjectionContext } from '@angular/core';
+import { Event, NavigationEnd, Router } from '@angular/router';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable } from 'rxjs';
+import { filter } from 'rxjs/operators'; | ```suggestion
import { filter, type Observable } from 'rxjs';
``` |
ngxtension-platform | github_2023 | typescript | 52 | ngxtension | eneajaho | @@ -0,0 +1,22 @@
+import { Injector, inject, runInInjectionContext } from '@angular/core';
+import { Event, NavigationEnd, Router } from '@angular/router';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable } from 'rxjs';
+import { filter } from 'rxjs/operators';
+
+/**
+ * Creates an Ob... | Should we call it injectNavigationEnd ?
Because that's what we do, we inject the router and return the navigation end.
This way it will be understood correctly what it does.
Just like we have injectResize.
What do you think @nartc @va-stefanek ? |
ngxtension-platform | github_2023 | others | 53 | ngxtension | nartc | @@ -55,7 +55,15 @@ We will review your PR as soon as possible, and your contribution will be greatl
Most likely, you'll need to create new secondary entry point to put the new utility in. To create entry point, use the following command:
```shell
-pnx nx g local-plugin:entry-point <name-of-your-utility> --library=n... | ```suggestion
pnpm exec nx g local-plugin:entry-point <name-of-your-utility> --library=ngxtension --skip-module
``` |
ngxtension-platform | github_2023 | others | 53 | ngxtension | nartc | @@ -0,0 +1,52 @@
+---
+title: call apply Pipes
+description: ngxtension/call-apply
+---
+
+`callPipe` and `applyPipe` are simple standalone pipes that simplify the calling of a PURE functions passing params to it, they take advantage of the "memoization" offerd by pure pipes in Angular, and enforces that you use them o... | ```suggestion
`callPipe` and `applyPipe` are simple standalone pipes that simplify the calling of PURE functions passing params to it; they take advantage of the "memoization" offered by pure pipes in Angular, and ensure that you use them only with PURE functions (aka if you use this inside the body function they thro... |
ngxtension-platform | github_2023 | others | 53 | ngxtension | nartc | @@ -0,0 +1,52 @@
+---
+title: call apply Pipes
+description: ngxtension/call-apply
+---
+
+`callPipe` and `applyPipe` are simple standalone pipes that simplify the calling of a PURE functions passing params to it, they take advantage of the "memoization" offerd by pure pipes in Angular, and enforces that you use them o... | ```suggestion
Both `CallPipe` and `ApplyPipe` need a PURE function or method to invoke (aka you can't use `this` in the function body), the difference between the two is only in that invocation order and that `|call` is suitable only for function with 1-param, instead `|apply` works for function with any number of par... |
ngxtension-platform | github_2023 | typescript | 53 | ngxtension | nartc | @@ -0,0 +1,44 @@
+import { Pipe, PipeTransform } from '@angular/core';
+
+const error_this = function () {
+ throw new Error(
+ `DON'T USE this INSIDE A FUNCTION CALLED BY | call OR | apply IT MUST BE A PURE FUNCTION!`
+ );
+};
+const NOTHIS = !('Proxy' in window)
+ ? Object.seal({})
+ : new Proxy(
+ {},
+ {
+ ... | ```suggestion
transform<TFunction extends (...args: any[]) => any>(fn: TFunction, ...args: Parameters<TFunction>): ReturnType<TFunction> {
``` |
ngxtension-platform | github_2023 | typescript | 53 | ngxtension | nartc | @@ -0,0 +1,44 @@
+import { Pipe, PipeTransform } from '@angular/core';
+
+const error_this = function () {
+ throw new Error(
+ `DON'T USE this INSIDE A FUNCTION CALLED BY | call OR | apply IT MUST BE A PURE FUNCTION!`
+ );
+};
+const NOTHIS = !('Proxy' in window)
+ ? Object.seal({})
+ : new Proxy(
+ {},
+ {
+ ... | ```suggestion
transform<TFunction extends (...args: any[]) => any>(value: Parameters<TFunction>[0], fn: TFunction): ReturnType<TFunction> {
```
We can use the same approach for `call` |
ngxtension-platform | github_2023 | typescript | 53 | ngxtension | nartc | @@ -23,7 +23,7 @@ const NOTHIS = !('Proxy' in window)
standalone: true,
})
export class CallPipe implements PipeTransform {
- transform(value: any, args?: Function): any {
+ transform<T = any, R = any>(value: T, args?: (param?: T) => R): R { | ```suggestion
transform<T = any, R = any>(value: T, args?: (param: T) => R): R {
```
If you make `param?: T` then it doesn't work because TypeScript will complain that `T | undefined is not assignable to T` |
ngxtension-platform | github_2023 | others | 40 | ngxtension | nartc | @@ -0,0 +1,44 @@
+---
+title: ifValidator
+description: ngxtension/if-validator
+---
+
+`ifValidator` or `ifAsyncValidator` are simple utility functions for help to change dynamically validation of Angular Reactive Form
+
+```ts
+import { ifValidator } from 'ngxtension/if-validation';
+```
+
+## Usage
+
+`ifValidator` ... | ```suggestion
`ifValidator` accepts a callback condition and `ValidatorFn` or `ValidatorFn[]`.
``` |
ngxtension-platform | github_2023 | others | 40 | ngxtension | nartc | @@ -0,0 +1,32 @@
+{
+ "name": "ngxtension/if-validator",
+ "$schema": "../../../node_modules/nx/schemas/project-schema.json",
+ "projectType": "library",
+ "sourceRoot": "libs/ngxtension/if-validator/src",
+ "targets": {
+ "test": {
+ "executor": "@nx/jest:jest",
+ "outputs": ["{workspaceRoot}/coverage/{projectRoo... | ```suggestion
"jestConfig": "libs/ngxtension/jest.config.ts",
"testPathPattern": ["if-validator"],
"passWithNoTests": true
``` |
ngxtension-platform | github_2023 | typescript | 40 | ngxtension | nartc | @@ -0,0 +1,48 @@
+import {
+ AbstractControl,
+ AsyncValidatorFn,
+ FormControl,
+ ValidatorFn,
+} from '@angular/forms';
+import { of } from 'rxjs';
+
+/**
+ * Simple Validation with If condition
+ */
+export function ifValidator(
+ condition: (control: FormControl) => boolean,
+ validatorFn: ValidatorFn | ValidatorFn... | nit: unnecessary `else` |
ngxtension-platform | github_2023 | typescript | 40 | ngxtension | nartc | @@ -0,0 +1,35 @@
+import { CommonModule } from '@angular/common';
+import { Component } from '@angular/core';
+import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
+import { ifValidator } from 'ngxtension/if-validator';
+
+@Component({
+ selector: 'my-app', | nit: you don't need `selector` for routed component.
```suggestion
``` |
ngxtension-platform | github_2023 | typescript | 40 | ngxtension | nartc | @@ -0,0 +1,35 @@
+import { CommonModule } from '@angular/common';
+import { Component } from '@angular/core';
+import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms';
+import { ifValidator } from 'ngxtension/if-validator';
+
+@Component({
+ selector: 'my-app',
+ standalone: true,
+ imports: [Comm... | ```suggestion
export default class IfValidator {
``` |
ngxtension-platform | github_2023 | others | 29 | ngxtension | eneajaho | @@ -0,0 +1,13 @@
+---
+title: Introduction
+description: What is ngxtension?
+---
+
+`ngxtension` is a utilities library for [Angular](https://angular.io). It consists of a variety of utilities that make Angular development easier and more consistent.
+
+The project is kick-started by [Chau](https://github.com/nartc) a... | ```suggestion
Find yourself adding something over and over again to every Angular projects? That is something we want to have in `ngxtension`. We intend for `ngxtension` to be "_anything goes_" but with careful consideration as well as up-to-standard Angular code so that `ngxtension` can become a one-stop shop for eve... |
ngxtension-platform | github_2023 | typescript | 23 | ngxtension | nartc | @@ -0,0 +1,43 @@
+import { DestroyRef, inject, Injector, WritableSignal } from '@angular/core';
+import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
+import { assertInjector } from 'ngxtension/assert-injector';
+import { Observable, Subscription } from 'rxjs';
+
+/**
+ * Connects a signal to an observable ... | suggestion: this `injector` is guaranteed to be an `Injector` instance so `|| inject(DestroyRef)` won't be reached at all |
ngxtension-platform | github_2023 | typescript | 23 | ngxtension | nartc | @@ -0,0 +1,163 @@
+import {
+ Component,
+ DestroyRef,
+ inject,
+ Injector,
+ OnInit,
+ signal,
+} from '@angular/core';
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { Subject, take } from 'rxjs';
+import { connect } from './connect';
+
+describe(connect.name, () => {
+ describe('connect... | suggestion: you can use `TestBed.createComponent()` API instead of `configureTestingModule().compileComponents()` |
ngxtension-platform | github_2023 | typescript | 22 | ngxtension | nartc | @@ -0,0 +1,35 @@
+import { DestroyRef, assertInInjectionContext, inject } from '@angular/core';
+import { ReplaySubject } from 'rxjs';
+
+/**
+ * Injects the `DestroyRef` service and returns a `ReplaySubject` that emits
+ * when the component is destroyed.
+ *
+ * @throws {Error} If no `DestroyRef` is found.
+ * @retur... | suggestion: let's have `injectDestroy` accept an `Injector` so it is consistent with the rest. |
ngxtension-platform | github_2023 | typescript | 22 | ngxtension | nartc | @@ -0,0 +1,51 @@
+import { Component, OnInit } from '@angular/core';
+import {
+ ComponentFixture,
+ TestBed,
+ fakeAsync,
+ tick,
+} from '@angular/core/testing';
+import { interval, takeUntil } from 'rxjs';
+import { injectDestroy } from './inject-destroy';
+
+describe(injectDestroy.name, () => {
+ describe('emits wh... | suggestion: you can use `TestBed.createComponent()` API instead of `configureTestingModule().compileComponents()` |
ngxtension-platform | github_2023 | typescript | 11 | ngxtension | nartc | @@ -1 +1 @@
-export const greeting = 'Hello World!';
+export * from './assert-injector'; | comment: oh damn I forgot? LOL |
ngxtension-platform | github_2023 | typescript | 11 | ngxtension | nartc | @@ -0,0 +1,203 @@
+import {Component, inject, Injector, Input, OnInit, Signal, signal} from '@angular/core';
+import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
+import {BehaviorSubject, delay, filter, map, of, pipe, startWith, Subject, switchMap,} from 'rxjs';
+import {computedFrom} from... | suggestion: use the function name
```suggestion
describe(computedFrom.name, () => {
``` |
ngxtension-platform | github_2023 | typescript | 11 | ngxtension | nartc | @@ -0,0 +1,203 @@
+import {Component, inject, Injector, Input, OnInit, Signal, signal} from '@angular/core';
+import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
+import {BehaviorSubject, delay, filter, map, of, pipe, startWith, Subject, switchMap,} from 'rxjs';
+import {computedFrom} from... | comment: `JsonPipe` is not needed right? |
ngxtension-platform | github_2023 | typescript | 5 | ngxtension | eneajaho | @@ -0,0 +1,153 @@
+import {
+ Host,
+ InjectionToken,
+ Optional,
+ Self,
+ SkipSelf,
+ inject,
+ type FactoryProvider,
+ type InjectOptions,
+ type Provider,
+ type Type,
+} from '@angular/core';
+
+type CreateInjectionTokenDep<TTokenType> =
+ | Type<TTokenType>
+ // NOTE: we don't have an AbstractType
+ | (abstract n... | Do we care about cases where we want to create EnvironmentProviders ?
Maybe another param?
Would it be better if we add an object for options and not leave them as separate param ? |
opencommit | github_2023 | typescript | 446 | di-sukharev | di-sukharev | @@ -0,0 +1,12 @@
+import { OpenAiEngine, OpenAiConfig } from './openAi';
+
+export interface DeepseekConfig extends OpenAiConfig {}
+
+export class DeepseekEngine extends OpenAiEngine {
+ constructor(config: DeepseekConfig) {
+ super({
+ ...config,
+ baseURL: 'https://api.deepseek.com/v1'
+ });
+ }
+} | this should implement the method from OpenAiEngine, otherwise it has nothing to call, you can copy the same one from OpenAIEngine |
opencommit | github_2023 | others | 436 | di-sukharev | di-sukharev | @@ -98,6 +99,7 @@
"ini": "^3.0.1",
"inquirer": "^9.1.4",
"openai": "^4.57.0",
+ "zod": "^3.23.8" | ```suggestion
"zod": "^3.23.8",
``` |
opencommit | github_2023 | typescript | 436 | di-sukharev | di-sukharev | @@ -0,0 +1,82 @@
+import axios from 'axios';
+import { Mistral } from '@mistralai/mistralai';
+import { OpenAI } from 'openai';
+import { GenerateCommitMessageErrorEnum } from '../generateCommitMessageFromGitDiff';
+import { tokenCount } from '../utils/tokenCount';
+import { AiEngine, AiEngineConfig } from './Engine';
... | this wont be hit |
opencommit | github_2023 | typescript | 434 | di-sukharev | di-sukharev | @@ -148,26 +148,29 @@ ${chalk.grey('ββββββββββββββββββ')}`
process.exit(0);
}
} else {
+ const skipOption = `Don't push` | ```suggestion
const skipOption = `don't push`
``` |
opencommit | github_2023 | typescript | 420 | di-sukharev | di-sukharev | @@ -36,6 +36,16 @@ const checkMessageTemplate = (extraArgs: string[]): string | false => {
return false;
};
+// remove all args after '--' | pls remove comments |
opencommit | github_2023 | typescript | 420 | di-sukharev | di-sukharev | @@ -111,6 +111,26 @@ const getOneLineCommitInstruction = () =>
? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to p... | i think this function should accept an argument `context: string`, wdyt? |
opencommit | github_2023 | typescript | 420 | di-sukharev | di-sukharev | @@ -111,6 +111,26 @@ const getOneLineCommitInstruction = () =>
? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to p... | π«‘ |
opencommit | github_2023 | typescript | 420 | di-sukharev | di-sukharev | @@ -197,6 +199,7 @@ ${chalk.grey('ββββββββββββββββββ')}`
export async function commit(
extraArgs: string[] = [],
+ context: string = '', | exactly |
opencommit | github_2023 | typescript | 338 | di-sukharev | imakecodes | @@ -1,17 +1,20 @@
-import axios, { AxiosError } from 'axios';
+import axios from 'axios';
import { ChatCompletionRequestMessage } from 'openai';
import { AiEngine } from './Engine';
+import {
+ getConfig
+} from '../commands/config';
+
+const config = getConfig();
+
export class OllamaAi implements AiEngine {
... | Why not?
```
`${config?.OCO_OLLAMA_BASE_PATH}/api/chat`;
``` |
opencommit | github_2023 | typescript | 396 | di-sukharev | di-sukharev | @@ -96,15 +96,9 @@ ${chalk.grey('ββββββββββββββββββ')}`
const remotes = await getGitRemotes();
// user isn't pushing, return early
- if (config?.OCO_GITPUSH === false)
+ if (config?.OCO_GITPUSH === false || !remotes.length)
return
- if (!remotes.length) { | i now get what you mean, but i would keep this lines, especially the `if (stdout) outro(stdout);` log, because otherwise user won't see why `push` is not working bc of the silent return on line `100` |
opencommit | github_2023 | typescript | 375 | di-sukharev | di-sukharev | @@ -13,9 +13,11 @@ export function getEngine(): AiEngine {
if (provider?.startsWith('ollama')) {
const ollamaAi = new OllamaAi();
- const model = provider.split('/')[1];
- if (model) ollamaAi.setModel(model);
-
+ const model = provider.replace('ollama/', ''); | @xtliu97 wont the change from `split` to `replace` affect anything else? |
opencommit | github_2023 | typescript | 348 | di-sukharev | github-advanced-security[bot] | @@ -239,6 +259,15 @@
'Must be true or false'
);
+ return value;
+ },
+ [CONFIG_KEYS.OCO_AZURE_ENDPOINT](value: any) {
+ validateConfig(
+ CONFIG_KEYS.OCO_AZURE_ENDPOINT,
+ value.includes('openai.azure.com'), | ## Incomplete URL substring sanitization
'[openai.azure.com](1)' can be anywhere in the URL, and arbitrary hosts may come before or after it.
[Show more details](https://github.com/di-sukharev/opencommit/security/code-scanning/5) |
opencommit | github_2023 | typescript | 269 | di-sukharev | di-sukharev | @@ -0,0 +1,43 @@
+import axios, { AxiosError } from 'axios';
+import { ChatCompletionRequestMessage } from 'openai';
+import { AiEngine } from './Engine';
+
+export class OllamaAi implements AiEngine {
+ async generateCommitMessage(
+ messages: Array<ChatCompletionRequestMessage>
+ ): Promise<string | undefined> {... | please remove comments |
opencommit | github_2023 | typescript | 64 | di-sukharev | di-sukharev | @@ -0,0 +1,12 @@
+const models = [
+ 'gpt-3.5-turbo',
+ 'text-davinci-003', | davinci wont work as it's not the same openAI API endpoint, we use `CreateChatCompletion` for 3.5 and 4, but `CreateCompletion` for < 3.5 |
opencommit | github_2023 | others | 221 | di-sukharev | di-sukharev | @@ -123,6 +124,7 @@ OCO_OPENAI_MAX_TOKENS=<max response tokens from OpenAI API>
OCO_OPENAI_BASE_PATH=<may be used to set proxy path to OpenAI api>
OCO_DESCRIPTION=<postface a message with ~3 sentences description>
OCO_EMOJI=<add GitMoji>
+OCO_EMOJI_POSITION_BEFORE_DESCRIPTION=<add GitMoji beofre description> | ```suggestion
OCO_EMOJI_POSITION_BEFORE_DESCRIPTION=<add GitMoji before description>
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.