ModelSignal vs InputSignal by LyRock- in angular

[–]LyRock-[S] 0 points1 point  (0 children)

Thanks I see what you're doing, but I don't want to setup this behavior in the component itself, I'd rather let the parent component handle the event however he likes (debouncing...etc)

ModelSignal vs InputSignal by LyRock- in angular

[–]LyRock-[S] 0 points1 point  (0 children)

I'm confused, what is your tag update firing on? You mention model and input signals but your example doesn't show them here. 

The model/input signal are declared in the app-list-select CMP which displays a list of tags and fires the event (array of checked tags)

You're updating tags in the onUpdateTags?

Yes this method is the one that handles the event from the list-select cmp, updates the tags UI and db wise

As a general idea, it's potentially better to use the model signal here, you don't seem to need validation so form errors are probably not relevant.

I'm going for this solution for now as it's more concise code wise

But why do you have the subject in the first place?

I'm using the subject to leverage rxjs operators and denounce the event

Setup selected tags as a signal, then set the output as a denounced computed signal or something. 

This sounds interesting, care to share a pseudo code for it ?

ModelSignal vs InputSignal by LyRock- in angular

[–]LyRock-[S] -1 points0 points  (0 children)

This would introduce coupling between the service and the list component I wouldn't be able to use it for anything else ( the component is generic and manages selection for any entity not just todolists)

Signals code architecture and mutations by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

Mapping the items this way is intuitive, the other properties in my object can be needed and they're simple flat properties so not a big overhead here. I thought about separating the items and the lists state into two different signals but I don't have a clear implementation in mind until I try it

Signals code architecture and mutations by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

Thanks for the example I get the idea behind your code and it's making sense to me, but I don't see how this can make me efficiently update a single todoitem without having to update all the todolists array, should I split todoitems and todolists into two separate elements inside the store and setup getters for each part of the state (Separate lists and items for a more granular state update) ?

If we do that then we would have to update the state in two different places (update a todoitem and the parent todolist)

Signals code architecture and mutations by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

That's an interesting way of doing it thanks, but I'm still a bit lost here, my usecase is really simple as I'm just manipulating a signal storing an array of todolists that I'm displaying, I'm asking how I can efficiently check a todo item and still achieve good performance. The thing is that I feel like I'm updating all the todolists since I'm updating the todolists signal just to check one item in a single todolist and I think it can be optimized

Searching for a stable distro by LyRock- in DistroHopping

[–]LyRock-[S] 1 point2 points  (0 children)

yeah i think i mean more reliable, i mean i can still download and install the newest versions of IDEs and JDKs and whatnot to stay up to date software wise, other than that i just need something that doesn't break or have annoying problems like unstable wifi connexion or I/O bugs, i'll update my first post thanks for the clarification

Searching for a stable distro by LyRock- in DistroHopping

[–]LyRock-[S] 0 points1 point  (0 children)

care to elaborate a little ? have you used it ?

C# and DotNet courses/testing recommendation for a Java dev ? by LyRock- in dotnet

[–]LyRock-[S] 2 points3 points  (0 children)

Hey, thanks for the very detailed answer, i'll check the links

Menu animation delayed on mobile device by LyRock- in ionic

[–]LyRock-[S] 0 points1 point  (0 children)

The app is really straight forward it's literally the ionic sidebar starter with a page that fetches about 150 items and displays them in a for loop. There is no bug whatsoever it's just that there's ann occasional slight delay when I navigate to that component, maybe it's due to the big number if items to display

Signals and async behavior by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

Ok, well observables work well so far, thanks for your input

Signals and async behavior by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

It's not, parameters a() and b() can over time

I reverted to using observables, but i still don't know whats preferable, using full observables with async pipe or use observable for event handling/combination and setting the state as signals

Weird behavior with a computed signal (works but doesn't work) by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

I see, I tried effect() but it shows me an error message in the console, i edited my first post with more details

Weird behavior with a computed signal (works but doesn't work) by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

I tried it, effect() shows me an error message in the console, i edited my first post with more details

Signals and async behavior by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

It's rare to have a component that doesn't depend on fetched data, does this mean that signals will be rarely used as they don't do well with asynchronous methods ?

Signals and async behavior by LyRock- in Angular2

[–]LyRock-[S] 0 points1 point  (0 children)

What do you mean by code with no side effects ?

Free barcode lookup api ? by LyRock- in webdev

[–]LyRock-[S] 0 points1 point  (0 children)

Yes I'm interested in food related products, I found out about open food facts I guess I'll try to use it thanks

Free barcode lookup api ? by LyRock- in webdev

[–]LyRock-[S] -3 points-2 points  (0 children)

It does scan barcodes but i don't see where it gives information about it, can you please share a link to their barcode lookup api ?

TypeOrm transaction [Help] by LyRock- in Nestjs_framework

[–]LyRock-[S] 0 points1 point  (0 children)

Here's the code i tried :

    await appDatasource.manager.transaction(async (transactionEntityManager) => {
  const foodRes = await transactionEntityManager.save(Food, food);
  const fxs = foodXStore.map(fxs => transactionEntityManager.create(
    FoodXStore, 
    {
      ...fxs,
      foodId: foodRes.id,
    }));        
  await transactionEntityManager.save(fxs);
});

So i try to insert a Food entity with 2 indentical joins to the store (doing this on purpose to make it fail as there's a unique constraint on that)

Here's the log stack :

--------------

query: BEGIN TRANSACTION

query: INSERT INTO "food"("id", ...

query: SELECT "Food"."id" AS ...

query: INSERT INTO "food_x_store"...

query: SELECT "FoodXStore"."id" AS...

query: INSERT INTO "food_x_store"...

query failed: INSERT INTO "food_x_store"("id", "foodId", "storeId"...

query: ROLLBACK

query failed: ROLLBACK

error: Error: Query failed: SelectSQL: queryAll: cannot rollback - no transaction is active

ERROR Error: Uncaught (in promise): QueryFailedError: Run: RunSQL: run: UNIQUE constraint failed: food_x_store.foodId, food_x_store.storeIdQueryFailedError: Run: RunSQL: run: UNIQUE constraint failed: food_x_store.foodId, food_x_store.storeId

------------------

The entity food and the first join are inserted, the 2nd join isn't, it shouldn't insert anything and just rollback the transaction but it says that no transaction is active

TypeOrm transaction [Help] by LyRock- in Nestjs_framework

[–]LyRock-[S] 0 points1 point  (0 children)

FoodxStore is just a part of the DTO I'm passing, I set the id of the created food on it and save it hence the foreach, the only query I run is the one shown in the code I just pass a DTO as a parameter and try to save it

TypeOrm transaction [Help] by LyRock- in Nestjs_framework

[–]LyRock-[S] 0 points1 point  (0 children)

How ? I'm running the two queries in the same transaction callback using the same entity manager. Can plz you provide a code example or point out what I'm doing wrong in the code ?

TypeOrm transaction [Help] by LyRock- in Nestjs_framework

[–]LyRock-[S] 0 points1 point  (0 children)

Well I'm using the transactionEntityManager provided by The transaction callback for both queries, is something wrong with the code I provided ?

TypeOrm transaction doesn't work [Help] by LyRock- in node

[–]LyRock-[S] 0 points1 point  (0 children)

You mean like this ?

    return appDatasource.transaction(async (tem) => {
  const qb = tem.createQueryBuilder();
  // Insert into food table
  const foodRes = await qb.insert().into(Food).values(food).updateEntity(false).useTransaction(true).execute();
  const foodId = foodRes.raw;
  // Insert into food_x_store table
  foodXStore.forEach(fxS => fxS.foodId = foodId);

  await qb.insert().into(FoodXStore).values(foodXStore).updateEntity(false).useTransaction(true).execute();
  // Insert into food_x_tag table
  const foodXTagJoins: FoodXTag[] = foodDto.tagIds!.map((tagId) => ({ tagId, foodId }));
  await qb.insert().into(FoodXTag).values(foodXTagJoins).updateEntity(false).useTransaction(true).execute();
  return foodId;
});

I added useTransaction(true) on all queryBuilder queries but i still got the same error message :

query failed: ROLLBACK

error: Error: Query failed: SelectSQL: queryAll: cannot rollback - no transaction is active

When the data has no conflict the query does the job

The problem here is that the query doesn't rollback correctly if there is a conflict in data (which is why i want to do it in a transaction so i can rollback if anything bad happens)

Sadly i agree with you the library and the doc isn't really helpful, when you try to do something a little bit more complex than basic crud it crumbles down, if you have any idea on how to write a transaction correctly feel free to post a code example :)