Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 10 20:19

    greenkeeper[bot] on @types

    (compare)

  • Dec 10 20:05

    greenkeeper[bot] on @types

    chore(package): update @types/n… chore(package): update lockfile… (compare)

  • Dec 10 19:28
    greenkeeper[bot] commented #698
  • Dec 10 19:28

    greenkeeper[bot] on @types

    chore(package): update @types/c… chore(package): update lockfile… (compare)

  • Dec 10 06:48
    Sawtaytoes commented #674
  • Dec 09 21:38

    greenkeeper[bot] on @types

    (compare)

  • Dec 09 21:30

    greenkeeper[bot] on @types

    chore(package): update @types/n… chore(package): update lockfile… (compare)

  • Dec 09 18:52
    greenkeeper[bot] commented #697
  • Dec 09 18:46

    greenkeeper[bot] on @typescript-eslint

    (compare)

  • Dec 09 18:46

    greenkeeper[bot] on @typescript-eslint

    chore(package): update @typescr… chore(package): update lockfile… (compare)

  • Dec 09 18:30

    greenkeeper[bot] on @typescript-eslint

    chore(package): update @typescr… chore(package): update lockfile… (compare)

  • Dec 09 13:40

    greenkeeper[bot] on @types

    (compare)

  • Dec 09 13:14

    greenkeeper[bot] on @types

    chore(package): update @types/n… chore(package): update lockfile… (compare)

  • Dec 08 21:03
    greenkeeper[bot] labeled #699
  • Dec 08 21:03
    greenkeeper[bot] opened #699
  • Dec 08 21:03

    greenkeeper[bot] on conventional-changelog-cli-2.0.30

    chore(package): update conventi… chore(package): update lockfile… (compare)

  • Dec 05 08:11
    evertbouw closed #696
  • Dec 05 01:54
    GravesDXD commented #696
  • Dec 04 18:02
    csvn commented #681
  • Dec 04 17:58
    csvn commented #681
Kevin Ghadyani
@Sawtaytoes
@spsaucier You saw it already, but for any lurkers in here, I'll post the solution for them as well:
import { ajax } from 'rxjs/ajax'
import { createEpicMiddleware } from 'redux-observable'
const epicMiddleware = store => {
  const originalEpicMiddleware = (
    createEpicMiddleware({
      dependencies: {
        ajax,
        dispatch: store.dispatch,
      },
    })
  )
  const storeMiddleware = originalEpicMiddleware(store)
  epicMiddleware.run = originalEpicMiddleware.run
  return storeMiddleware
}
export default epicMiddleware
dcs3spp
@dcs3spp_gitlab

OK, many thanks @Sawtaytoes I managed to get it compiling. It was the suspected type declarations issue. When using Typescript, the action types declared in the epic signature must be a subset of all action types that were declared when the middleware was setup.

I had not instantiated an instance of new generic action and I had also not added it as a type to the RootAction(union of all action types). The RootAction still also contained some old action types from older architecture before refactoring.

The code compiled after doing this and refactoring my epic signature to:

  • Specify the subset of action types accepted as input to the epic
  • Specify the subset of action types output by the epic
Sven Ridder
@SvenRidder_twitter
I have one question to the distinctUntilChanged operator. I listen to a state update directly and use distinctUntilChanged operator to stop the pipeline. This works, but when the app is initialized at first time the code run through the complete pipeline. Is this normal or is it related to the init state ? Any hints what the problem could be ?
Kevin Ghadyani
@Sawtaytoes
@SvenRidder_twitter That's correct. I also sometimes listen state$ and use distinctUntilChanged as well. First, I map with a selector though. That operator will let the first value though and only other values if they're different.
Epaphrodis
@tysepa
help
Alice has two strings, initial and goal. She can remove some number of characters from initial, which will give her a subsequence of that string. A string with no deletions is still considered a subsequence of itself. Given these two strings, can you find the minimum number of subsequences of initial that, when appended together, will form goal? Functions minimumConcat() has two parameters: initial: the source string that you will get subsequences from goal: the target string that needs to be formed Input Format For some of our templates, we have handled parsing for you. If we do not provide you a parsing function, you will need to parse the input directly. In this problem, our input format is as follows: The first line is the initial String that we will be generating subsequences from The second line is the goal String to form Here is an example of the raw input: abc bcbac Expected Output Return the number of minimum possible subsequences of initial that can be appended together to form goal. If there are no possible solutions, return -1. Constraints Both initial and goal can only contain lowercase letters, [a - z]. Assume that the bounds of the length of the two strings are the following: 0 <= length of initial <= 100 0 <= length of goal <= 100000 Example Example minimumConcat() Input #1 initial: "xyz" goal: "xzyxz" Example Output #1 3 Solution #1 Our goal can be constructed from the following subsequences of initial: "xz" + "y" + "xz" Example minimumConcat() Input #2 initial: "abc" goal: "acdbc" Example Output #2 -1
Kevin Ghadyani
@Sawtaytoes
@tysepa I'd love to help you, but your question is one giant paragraph and looks like something off a Computer Science test 😝. I can't tell what you want. Do you have any code examples?
Epaphrodis
@tysepa

/**

  • @param {character[][]} grid
  • @return {number}
    */
    function numOffices(grid) {
    let result = 0;
    //Put your code here.
    let tup=function(grid, x,y, visited){

     if (x>0 || x > grid.length-1 || y < 0|| y > grid[x].length-1){
         return;
     }
      if (visited[x][y]=== true){
          visited[x][y]=true;
     }
    
     if (grid[x][y]==='0'){
    tup(grid, x-1, y, visited);
    tup(grid, x+1, y, visited);
    tup(grid, x, y-1, visited);
    tup(grid, x, y+1, visited);
    }
};
let visited =[];
for(let i=0; i<grid.length; i++){
    visited[i]=[];
}
for( let x=0; x<grid.lenght; i++){
    for (let y=0; y<grid[x].length;y++){
        if(!visited[x][y]&& grid[x][y]==='1'){
            result++;
            tup(grid,x,y, visited);
        }
        visited[x][y] = true;
    }
}


return result;

};

let height = parseInt(readline());
let width = parseInt(readline());
let grid = [];
for (var i = 0; i < height; i++) {
grid[i] = (readline() || "").split("");
}

print(numOffices(grid));

Kevin Ghadyani
@Sawtaytoes
@tysepa appreciate you adding code samples; although, I'm still confused what you're asking. Are you wanting to change this code into observable code? Have you tried doing this yourself?
Jim Rhodes
@jimjiminyjimjam_twitter
Just wondering if anyone can help me with an observable that needs to track two actions in sequence but from multiple devices...
const taskNextInQueue$ = (action$, state$) =>
  action$.pipe(
    ofType(TASK_SEND),
    mergeMap(action => {
      return action$.ofType(TASK_COMPLETE).pipe(
        filter(action2 => action2.deviceId == action.deviceId),
        switchMap(action => {
I only want the action to happen if the deviceID of both tasks match
but at the moment if TASK_SEND happens but a TASK_COMPLETE happens from another device its not getting to the switchmap
just to be clear - for every task I send to a device, I want to wait for the task to complete
Kevin Ghadyani
@Sawtaytoes

@jimjiminyjimjam_twitter This is a great problem to solve, and you have the right idea. You need some sort of namespace or idprop to dictate which observable is the correct TASK_COMPLETE listener.

A few things:

  1. You want to ensure you have a takeUntil in your inner observable so you don't have a memory leak with a bunch of TASK_COMPLETE listeners going.
  2. Make sure your action2.deviceId really is equal to your action.deviceId. In these situations, I've forgotten to add that prop or pass it into my action creator. Use a tap(console.log) or add a breakpoint on that filter line.
  3. .ofType isn't part of Redux-Observable v1 anymore right? Dunno if that's a typo in your example code or if that's your real code, but also make sure you''re piping in ofType like you do in TASK_SEND.
Jim Rhodes
@jimjiminyjimjam_twitter
@Sawtaytoes - great thanks. Yes so the filter I'm using is the deviceId, each device can only ever process one task at a time
I'm not sure I have a namespace available with the system I'm using other than deviceId. Each device would only ever get sent a task, then it completes then the next task is sent
Kevin Ghadyani
@Sawtaytoes

@jimjiminyjimjam_twitter By namespace, I just mean an id prop like how we have type, I would create a namespace prop on the action object.

I think I'm misunderstanding your issue. How does the architecture look? I assumed on this machine, TASK_SEND gets called and then a listener for TASK_COMPLETE is created for that same deviceId. That's what the code says at least. Whichever device has been sent a message has to respond to this machine with its deviceId and then TASK_COMPLETE is called. After that, another TASK_SEND action gets dispatched.

Jim Rhodes
@jimjiminyjimjam_twitter
@Sawtaytoes - yep that’s exactly it. So the only thing I think I’m now struggling with is the takeuntil? As I have multiple actions all the same type - The only way I’m distinguishing them by is device id. What would you suggest I use takeuntil with?
Kevin Ghadyani
@Sawtaytoes

@jimjiminyjimjam_twitter The issue here is that you're creating more listeners every time a task comes in and never getting rid of them. So basically, when a task is listed as "complete" for that device ID, then you should kill off that inner TASK_COMPLETE observable and stop listening to action$ on it.

Actually, with what you have, a simple take(1) would suffice. Normally I use takeUntil because I kill a listener on complete, but in your case, you're wanting to execute something else on complete so it's a bit different. Using take(1) will say, if a single TASK_COMPLETE comes in after the filter, then it's safe to end this observable when it's done processing.

Kevin Ghadyani
@Sawtaytoes

@jimjiminyjimjam_twitter

const taskNextInQueue$ = (action$, state$) =>
  action$.pipe(
    ofType(TASK_SEND),
    mergeMap(action => {
      return action$.ofType(TASK_COMPLETE).pipe(
        filter(action2 => action2.deviceId == action.deviceId),
        take(1), // PUT IT HERE
        switchMap(action => {

Based on your code, I'm assuming you're going to execute more tasks with switchMap. You might consider instead using map and pushing through another TASK_SEND action. Once you add that switchMap, the take(1) might not work like you think. Add a finalize operator to log a string when the inner TASK_COMPLETE observable completes to see if that's working properly.

Sung M. Kim
@dance2die
Ah I forgot about this channel and ended up creating an redux-observable/redux-observable#695 😅.
Would "this link in warning" shows 404 in this channel be fine?
Kevin Ghadyani
@Sawtaytoes
@dance2die I don't understand what you're saying, but making an issue on GitHub is fine. As far as I know, @jayphelps doesn't frequent this chat.
Sung M. Kim
@dance2die
Thanks @Sawtaytoes. I misunderstood why creating an issue could have had been a problem.
(must've have mixed it up with other communities' guidelines).
Nisim Joseph
@nisimjoseph

Hi, I encounter an issue with Epic.ts file which limits the Generic use of Output Action to extends Input. why is that?
My Output action doesn't need to extend the Input action and it quite limits the development.
https://github.com/redux-observable/redux-observable/blob/master/src/epic.ts

When I change the generic Output to extends Action it gives me more flexability.

xavier7179
@xavier7179
May I ask a general question that I'm not so sure it is covered (I read a lot online, including a great @Sawtaytoes post covering a lot of redux-observable examples)? Is there a nice and clean way to make an epic managing an ajax request to ignore any OF_STARTING_TYPE_ACTION while the actual request is not ended, in order to ensure only one ajax request per time is served?
Kevin Ghadyani
@Sawtaytoes
@xavier7179 That's actually more of an RxJS question :P. exhaustMap is what you want.
popoleeMaster
@popoleeMaster
Hello
Is there someone that could help me for a little problem I have ?
Kevin Ghadyani
@Sawtaytoes
@popoleeMaster Yes.
popoleeMaster
@popoleeMaster
THanks
I have the following code :
const goToItemEpic = (action$, state$): Observable<any> => action$.pipe(
    ofType(ItemsDetailsActions.goToItem),
    concatMap((action: {payload: {projectId: string; datastoreId: string; itemId: string}}) => {
        const projectId = ProjectSelectors.getCurrentProjectId(state$.value);
        if(action.payload.projectId !== projectId) {
            return of(ProjectActions.setCurrentProjectId({projectId: action.payload.projectId})).pipe(
                delay(1000),
                switchMap(() => {
                    return [
                        DatastoreActions.setCurrentDatastoreId({datastoreId: action.payload.datastoreId}),
                        ItemsActions.setCurrentItemId({ itemId: action.payload.itemId })
                    ];
                })
            )
        } else {
            return [
                DatastoreActions.setCurrentDatastoreId({datastoreId: action.payload.datastoreId}),
                ItemsActions.setCurrentItemId({ itemId: action.payload.itemId })
            ];
        }
    })
);
Basically, if(action.payload.projectId !== projectId) I would like to set the current project, and then after a delay (that I wish it to be another observable) I also dispatch 2 actions. But i can't manage to do it, maybe you can help @Sawtaytoes
like, setCurrentProjectId dispatch a series of action, the last beeing getDatastoresSuccess. I would like that after getDatastoresSuccess is executed, setCurrentDatastoreId, setCurrentItemId are dispatched
is it possible to do ?
Evert Bouw
@evertbouw
sure
return merge(
    of(ProjectActions.setCurrentProjectId({projectId: action.payload.projectId})),
    of(
        DatastoreActions.setCurrentDatastoreId({datastoreId: action.payload.datastoreId}),
        ItemsActions.setCurrentItemId({ itemId: action.payload.itemId })
    ).pipe(
        delay(1000)
    )
)
which is basically the same as using startWith but that might not read clearly in this case
return of(
    DatastoreActions.setCurrentDatastoreId({datastoreId: action.payload.datastoreId}),
    ItemsActions.setCurrentItemId({ itemId: action.payload.itemId })
).pipe(
    delay(1000),
    startWith(ProjectActions.setCurrentProjectId({projectId: action.payload.projectId}))
)
ImmortaL
@ImmRanneft
Guys, I don't know if you know someone who maintains redux-observable.js.org, but the example for "using react" is not working :) Not really dev-friendly to start with it.
Kevin Ghadyani
@Sawtaytoes
@ImmRanneft Could you link to it?
Either @evertbouw or @jayphelps or both are in charge of that site.
Evert Bouw
@evertbouw
I think the source for the docs have been updated, will need to regenerate the website
by updated I mean the examples have been removed
Evert Bouw
@evertbouw
ImmortaL
@ImmRanneft
:) Now it's not that disappointing, thank you
Kevin Mui
@kmui2
Hello, I'm guessing this might be the place to ping for help. I've recently been trying out redux-observable after using other patterns in thunks and sagas. Here's my question: https://stackoverflow.com/q/59187250/8109319.
Kevin Ghadyani
@Sawtaytoes
@kmui2 Are you still needing help? Looks like someone's already answered your question on StackOverflow. Main thing to note is you always setup an action$ listener before dispatching an action otherwise, you won't see it.
Kevin Ghadyani
@Sawtaytoes

@kmui2 I was going to edit the other StackOverflow answer, but didn't understand what the answerer was going for so I wrote my own response instead.

I wrote an article here about splitting observable pipelines to allow multiple actions to "fall through" and get automatically dispatched here: https://itnext.io/redux-observable-can-solve-your-state-problems-15b23a9649d7

What you're talking about is pretty standard for when I use Redux-Observable, but the confusion you had where pauseGame wasn't firing makes complete sense. In that case, I wrote a separate article about using dispatch anywhere in your pipeline instead of having the actions "fall through" and become automatically dispatched: https://dev.to/sawtaytoes/the-best-practice-anti-pattern-jj6