profile
viewpoint

GoogleCloudPlatform/cloud-bigtable-examples 189

Examples of how to use Cloud Bigtable both with GCE map/reduce as well as stand alone applications.

kkemple/tasker 8

A time tracking app with JIRA support and verbal and desktop notifications.

kolodny/ccolors 3

Cli Colors, a slightly improved version of npm's colors

kolodny/CacheSQL 1

CacheSQL class

kolodny/7XX-rfc 0

An RFC for a new series of HTTP status codes covering developer fouls.

kolodny/astexplorer 0

A web tool to explore the AST generated by various parsers.

kolodny/autochecker 0

Test your JavaScript modules simultaneously in 32 different versions of NodeJS

pull request commentkolodny/immutability-helper

Add support for "transactions"

Hi @simon0191 , thanks for the PR.

I'm not 100% sure what the use case for this feature is. It's already possible to update multiple parts of the state at once. For example this code updates both a.b and c.d:

Demo

import update from 'immutability-helper';

const state = {
  a: {
    b: 'ab',
  },
  c: {
    d: 'cd',
  }
};

const state2 = update(state, {
  a: {b: {$set: 'AB'}},
  c: {d: {$set: 'CD'}},
});

(window as any).app.innerHTML = JSON.stringify(state2, null, 2);
simon0191

comment created time in 3 days

pull request commentReactiveX/rxjs

feat(timeout): One timeout to rule them all

A couple of API points. This seems like a kitchen sink function (not a bad thing), in which case we may want to allow more flexibility. What do you think about replacing first and each with delayAllowed or timeAllowed and have it
take a number | Date | ((info: Info) => number | Date). That would also allow the more flexibility in subsequent items and can fine tune the time based on the current time, previous values, as well something like () => min(moment().add('4 seconds'), APP_DEADLINE).

Also the meta and with seem redundant and can be merged into a timeoutWith (not 100% on that name either TBH). Also I'm wondering if it makes sense for the timeoutWith to just become timeoutReason and be a string that's always wrapped in a TimeoutError, 95% of the time the user won't switch this to a plain obs value but if they didn't want it to actually throw they could just pipe directly on it

Taking your examples above it would turn into:

source$.pipe(
  timeout({
    // First item must happen by '10/22/2021, after that every 1 second
    timeAllowed: info => info.seen === 0 ? new Date('10/22/2021') : 1000
    timeoutReason: info => `Timeout out after ${info.seen} values. Reason: 'Too slow!'. Last value: ${info.lastValue}`,
  }
})
)


source$.pipe(
  timeout({ 
    // If the first value does not arrive within 4 seconds, timeout.
    // After that, values may arrive after any delay
    timeAllowed: info => info.seen === 0 ? 4000 : Infinity
  }).pipe(
    catchError(err =>
      of(`Timeout out after ${err.info.seen} values. Reason:''Too slow!''. Last value: ${error.info.lastValue}`);
    )
  ),
)

I know I kind of have the examples backwards where the first example throws and the second doesn't but I think the point still gets across.

Thoughts?

benlesh

comment created time in 14 days

startedmutil/nodejs-piwik-proxy

started time in 14 days

startedfranciscop/drive-db

started time in a month

pull request commentReactiveX/rxjs

Run mode updates 2

Nice!

benlesh

comment created time in a month

pull request commentReactiveX/rxjs

docs: Add the start of a glossary

This is amazing!! One small suggestion I had to make this more approachable for most folks (even if we're targeting "power" users: Can we include a giant snippet (or many small snippets) where we label things while giving concrete examples. I'm thinking of some code like this

import { Observable } from 'rxjs'; 

const thisIsTheObservable = new Observable(function thisIsTheProducer(thisIsTheObserver) {
  thisIsTheObserver.next('this value is being nexted');
  setTimeout(() => {
    thisIsTheObserver.complete();
  }, 1000);
  return function thisIsTheTeardown() {
    console.log('tearing down');
  }
})

const thisIsThePartialObserver = {
  next(value) { console.log('got:', value); },
  complete() { console.log('finished') }
}
const thisIsTheSubsription = thisIsTheObservable.subscribe(thisIsThePartialObserver);

const doneWithObservable = Math.random() > 0.5;

if (doneWithObservable) {
  thisIsTheSubsription.unsubscribe();
}

I'm sure some of the terms are not going to fit into this format but a large chunk will and will make those terms less esoteric.

benlesh

comment created time in a month

Pull request review commentReactiveX/rxjs

Prettier

     }   },   "lint-staged": {-    "*.js": [-      "eslint --fix",-      "git add"+    "src/**/*.ts": [+      "prettier --write"     ],+    "*.js": "eslint --cache --fix",     "*.ts": [-      "tslint --fix",-      "git add"-    ]+      "tslint --fix"

I think the latest lint-staged does this at the end by default

benlesh

comment created time in a month

Pull request review commentReactiveX/rxjs

Prettier

 export class Observable<T> implements Subscribable<T> {   /* tslint:disable:max-line-length */   pipe(): Observable<T>;   pipe<A>(op1: OperatorFunction<T, A>): Observable<A>;-  pipe<A, B>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): Observable<B>;-  pipe<A, B, C>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Observable<C>;-  pipe<A, B, C, D>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): Observable<D>;-  pipe<A, B, C, D, E>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>): Observable<E>;-  pipe<A, B, C, D, E, F>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>): Observable<F>;-  pipe<A, B, C, D, E, F, G>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>): Observable<G>;-  pipe<A, B, C, D, E, F, G, H>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>): Observable<H>;-  pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): Observable<I>;-  pipe<A, B, C, D, E, F, G, H, I>(op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>, ...operations: OperatorFunction<any, any>[]): Observable<unknown>;+  pipe<A, B>(

image

benlesh

comment created time in a month

Pull request review commentReactiveX/rxjs

Prettier

+{+  "trailingComma": "es5",+  "singleQuote": true,+  "requirePragma": true+}
. .
benlesh

comment created time in a month

pull request commentReactiveX/rxjs

fix(defer) allow passing () => any to observableFactory

OK, I think I've got it. Let me know if this is what you had in mind

kolodny

comment created time in a month

push eventkolodny/rxjs

Moshe Kolodny

commit sha dbc55e77938055a79fd63f772e9d85397383deec

fix(defer) revert to old declaration without void

view details

push time in a month

pull request commentReactiveX/rxjs

fix(defer) allow passing () => any to observableFactory

I think you should go back to #5449 and look at what was there before that PR's changes. In particular, this line seems to have been changed:

const source = input ? from(input as ObservableInput<ObservedValueOf<R>>) : EMPTY;

And the assertion was removed. If that doesn't help, I can look at this tomorrow, but, IMO, the gist of it is to go back to what it was before #5449, but remove the void business.

Got it, does that mean that this is no longer a type error?:

const a = defer(() => { throw new Error(); });
kolodny

comment created time in a month

pull request commentReactiveX/rxjs

fix(defer) allow passing () => any to observableFactory

We should simplify the types here to just be:

function defer<T>(callback: () => ObservableInput<T>): Observable<T>

Just getting back to this now, is looks like this causes some TS weirdness with union types

export function defer<T>(observableFactory: () => ObservableInput<T>): Observable<T> {
  return new Observable<T>(subscriber => {
    let input: ObservableInput<T>;
    try {
      input = observableFactory();
    } catch (err) {
      subscriber.error(err);
      return undefined;
    }
    const source = from(input);
    return source.subscribe(subscriber);
  });
}

defer(() => true ? of('3') : of(1)) // Type 'number' is not assignable to type 'string'

This also breaks https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/iif.ts#L99 image

Changing iif.ts to use ObservableInput or changing defer.ts to use SubscribableOrPromise doesn't fix the issue either.

Also this definition has the same issue as well:

export function defer<R>(observableFactory: () => ObservableInput<R>): Observable<ObservedValueOf<R>> {

I need to spend a bit more time on this to figure this out, it's possible I'm missing something obvious (and if so please point it out)

kolodny

comment created time in a month

push eventkolodny/react-compose-wrappers

Moshe Kolodny

commit sha 83ac29df93aac13f6c4005be65dbb1bd15335c20

use reduceRight for saner usage down the array

view details

push time in a month

startedmswjs/msw

started time in 2 months

pull request commentReactiveX/rxjs

fix(defer) allow passing () => any to observableFactory

I guess I misunderstood that comment then. I tried the changes in https://github.com/ReactiveX/rxjs/blob/362d1d4fc1d7f15e7168453ea640079d0ca19dba/src/internal/observable/defer.ts#L56-L57 but that causes a slew of other errors such as

it('should error with void functions', () => {
  const a = defer(() => {}); // $ExpectError
});

And functions that return undefined should be no problem, as undefined is not a valid ObservableInput.

I thought we wanted to reject functions that don't return an observablelike value

Are the current dtslint tests incorrect? Otherwise I don't see how else we can get the expected behavior without nested conditionals.

kolodny

comment created time in 2 months

PR opened ReactiveX/rxjs

Reviewers
fix(defer) allow passing () => any to observableFactory

Fixes #5511

+13 -2

0 comment

2 changed files

pr created time in 2 months

create barnchkolodny/rxjs

branch : defer-fn-any

created branch time in 2 months

startedmuralikg/puppetcam

started time in 2 months

Pull request review commentReactiveX/rxjs

Add ts-api-guardian

     "lint_src": "tslint -c tslint.json -p src/tsconfig.base.json \"src/**/*.ts\"",     "lint": "npm-run-all --parallel lint_*",     "dtslint": "tsc -b ./src/tsconfig.types.json && tslint -c spec-dtslint/tslint.json -p spec-dtslint/tsconfig.json \"spec-dtslint/**/*.ts\"",-    "prepublishOnly": "npm run build:package",+    "prepublishOnly": "npm run build:package && npm run lint && npm run test && npm run test:circular && npm run dtslint && npm run test:side-effects npm run api_guardian:verify",

There's no api_guardian:verify command

benlesh

comment created time in 2 months

Pull request review commentReactiveX/rxjs

fix(defer) Disallow passing () => undefined to observableFactory

 import { EMPTY } from './empty';  * @name defer  * @owner Observable  */-export function defer<R extends ObservableInput<any> | void>(observableFactory: () => R): Observable<ObservedValueOf<R>> {+export function defer<R extends ObservableInput<any> | void>(+  observableFactory: [R] extends [undefined] | [void] ? never : () => R+): Observable<ObservedValueOf<R>> {

Done, I've updated the tests and dstlint spec to reflect the changes

kolodny

comment created time in 2 months

push eventkolodny/rxjs

Moshe Kolodny

commit sha 14c8df37e1365c0361bb836296bd78d76018d6d1

address comments

view details

push time in 2 months

Pull request review commentReactiveX/rxjs

chore: deprecate old config options

 export function lastValueFrom<T>(source: Observable<T>) {       },     });   });-}+}

We should have an autoformatter that catches things like this

benlesh

comment created time in 2 months

Pull request review commentReactiveX/rxjs

chore: deprecate old config options

 export class Observable<T> implements Subscribable<T> {   }    /**-   * @method forEach+   * Used as a NON-CANCELLABLE means of subscribing to an observable, for use with

Is it worth mentioning rxjs-for-await? I'm 50/50

benlesh

comment created time in 2 months

Pull request review commentReactiveX/rxjs

chore: deprecate old config options

 export const config = {    * where a multicast can be broken for all observers by a downstream consumer with    * an unhandled error. DO NOT USE THIS FLAG UNLESS IT'S NEEDED TO BY TIME    * FOR MIGRATION REASONS.+   *+   * @deprecated remove in v8. As of version 8, RxJS will no longer support synchronous throwing

Good catch, I'm surprised this wasn't already "here be dragons"ed already

benlesh

comment created time in 2 months

PR closed DefinitelyTyped/DefinitelyTyped

feat(recoil) add Recoil typings Has Merge Conflict Revision needed

Please fill in this template.

  • [x] Use a meaningful title for the pull request. Include the name of the package modified.
  • [x] Test the change in your own code. (Compile and run.)
  • [x] Add or edit tests to reflect the change. (Run with npm test.)
  • [x] Follow the advice from the readme.
  • [x] Avoid common mistakes.
  • [x] Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If adding a new definition:

  • [x] The package does not already provide its own types, or cannot have its .d.ts files generated via --declaration
  • [x] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package.
  • [x] Create it with dts-gen --dt, not by basing it on an existing project.
  • [x] Represents shape of module/library correctly
  • [x] tslint.json should be present and it shouldn't have any additional or disabling of rules. Just content as { "extends": "dtslint/dt.json" }. If for reason the some rule need to be disabled, disable it for that line using // tslint:disable-next-line [ruleName] and not for whole package so that the need for disabling can be reviewed.
  • [x] tsconfig.json should have noImplicitAny, noImplicitThis, strictNullChecks, and strictFunctionTypes set to true.
+296 -0

7 comments

4 changed files

kolodny

pr closed time in 2 months

pull request commentkolodny/immutability-helper

Support complex specs inside of Maps in typescript

Published to v3.1.1

colekurk

comment created time in 2 months

release kolodny/immutability-helper

v3.1.1

released time in 2 months

created tagkolodny/immutability-helper

tagv3.1.1

mutate a copy of data without changing the original source

created time in 2 months

push eventkolodny/immutability-helper

Moshe Kolodny

commit sha e7b3bd578a751fb56fbe00e93b8164e23136d301

prepare for 3.1.1 release

view details

push time in 2 months

issue closedkolodny/immutability-helper

Consider switching to tiny-invariant or own invariant function

The use of invariant pulls in loose-envify which in turn pulls in js-tokens. This has little consequence when used with React since it already uses them, but when used outside React these are relatively heavy dependencies (as already noted in #126)

Also as noted in https://github.com/kolodny/immutability-helper/issues/83#issuecomment-401852092, this way of writing invariant checks can cause significant performance penalty, since the error message arguments are always evaluated (unless combined with a compile-time code rewriter, but this project doesn't do that)

I would like to suggest at a minimum switching to use tiny-invariant, which is compatible with invariant except that it does not provide the %s formatting. The library still works with compile-time code rewriters and does not have any dependencies (and is tiny itself).

And better would be to also run the code through a transformer as part of the build process so that the built code only evaluates error arguments if the condition fails (or see my suggested improvement to tiny-invariant https://github.com/alexreardon/tiny-invariant/issues/62 if a build-time transformation is not desirable).

closed time in 2 months

davidje13

PR merged kolodny/immutability-helper

Use internal invariant function

Also updates TS to the current latest to ensure we're not doing anything incorrect with types

closes #156 /cc @davidje13

+303 -1291

3 comments

5 changed files

kolodny

pr closed time in 2 months

push eventkolodny/immutability-helper

Moshe Kolodny

commit sha 317ae9f011347214aa88b1cd9cf6a5be15462325

Use internal invariant function (#158) * Use internal invariant function * Lazy eval messages * Expose invariant function Co-authored-by: Moshe Kolodny <kolodny@github.com>

view details

push time in 2 months

push eventkolodny/immutability-helper

Cole Kurkowski

commit sha 11d567fa18ae9c9dd3c67c996532e9eecc965853

Support complex specs inside of Maps in typescript (#162)

view details

Moshe Kolodny

commit sha cb29447432101e918d5d431258e07e5082bcc017

Merge branch 'master' into no-deps

view details

push time in 2 months

pull request commentkolodny/immutability-helper

Support complex specs inside of Maps in typescript

Great work, thanks!

colekurk

comment created time in 2 months

push eventkolodny/immutability-helper

Cole Kurkowski

commit sha 11d567fa18ae9c9dd3c67c996532e9eecc965853

Support complex specs inside of Maps in typescript (#162)

view details

push time in 2 months

PR merged kolodny/immutability-helper

Support complex specs inside of Maps in typescript

The MapSpec type was unnecessarily strict about the what could be allowed in $set commands.

Resolves #161

+6 -8

1 comment

2 changed files

colekurk

pr closed time in 2 months

issue closedkolodny/immutability-helper

Exported MapSpec type does not allow specs in typescript which seem to work correctly in JS

Version: 3.0.2 Typescript: 3.7.5

The example code in this comment (shown below) does not compile in typescript.

var state = new Map([
    ['mapKey', { banana: 'yellow', apple: ['red'], blueberry: 'purple', obj: {a:true} }]
]);

var updatedState = update(state, {
    ['mapKey']: {
        apple: { $set: ['green', 'red'] },
        obj: {$toggle: ['a']}
    }
});

tsc error:

Type '{ apple: { $set: string[]; }; obj: { $toggle: string[]; }; }' is not assignable to type '{ $set: { banana: string; apple: string[]; blueberry: string; obj: { a: boolean; }; }; }'.
  Object literal may only specify known properties, and 'apple' does not exist in type '{ $set: { banana: string; apple: string[]; blueberry: string; obj: { a: boolean; }; }; }'

Since the object is a literal the error is kind of verbose, but the tl;dr is that typescript thinks the $set command can only accept a value of the same type as the Map's value type, and not additional commands operating on the current value in the map.

Running the sample code in a plain JS environment (or presumably by forcing update to use any as the spec type) produces the expected result, so I think this is strictly a problem with the exported typescript types.

It's also possible typescript is inferring a type weirdly, but I'm not sure what I would need to change to make it work correctly.

closed time in 2 months

colekurk

pull request commentDefinitelyTyped/DefinitelyTyped

Add type definitions for recoil

I've done some work independently, not realizing this PR existed. I have a couple of the tricky cases worked out. The types are pretty well tested and are quite robust. Feel free to incorporate anything from that branch to this PR.

https://github.com/kolodny/DefinitelyTyped/commit/7bae6984215fbe1ac784959cffbd44008cb8fa94#diff-536a520cf5eea35920533711cf917823

csantos42

comment created time in 2 months

pull request commentDefinitelyTyped/DefinitelyTyped

feat(recoil) add Recoil typings

Whoops. I searched for recoil before creating this PR, not sure how I missed that

kolodny

comment created time in 2 months

push eventkolodny/DefinitelyTyped

Moshe Kolodny

commit sha 7bae6984215fbe1ac784959cffbd44008cb8fa94

feat(recoil) add Recoil typings

view details

push time in 2 months

create barnchkolodny/DefinitelyTyped

branch : recoil

created branch time in 2 months

PR opened DefinitelyTyped/DefinitelyTyped

feat(recoil) add Recoil typings

Please fill in this template.

  • [x] Use a meaningful title for the pull request. Include the name of the package modified.
  • [x] Test the change in your own code. (Compile and run.)
  • [x] Add or edit tests to reflect the change. (Run with npm test.)
  • [x] Follow the advice from the readme.
  • [x] Avoid common mistakes.
  • [x] Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If adding a new definition:

  • [x] The package does not already provide its own types, or cannot have its .d.ts files generated via --declaration
  • [x] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package.
  • [x] Create it with dts-gen --dt, not by basing it on an existing project.
  • [x] Represents shape of module/library correctly
  • [x] tslint.json should be present and it shouldn't have any additional or disabling of rules. Just content as { "extends": "dtslint/dt.json" }. If for reason the some rule need to be disabled, disable it for that line using // tslint:disable-next-line [ruleName] and not for whole package so that the need for disabling can be reviewed.
  • [x] tsconfig.json should have noImplicitAny, noImplicitThis, strictNullChecks, and strictFunctionTypes set to true.
+298 -0

0 comment

4 changed files

pr created time in 2 months

issue commentReactiveX/rxjs

Why is the pluck deprecated?

pluck('prop') is a shorthand for map(x => x.prop), the main advantage to using pluck was the path traversal safety, meaning you can do

pluck('foo', 'bar', 'baz')

and this would be fine even if the emitted value didn't have a foo property. Contrast this with
map(x => x.foo.bar.baz) which will error if the emitted value doesn't have a foo property

With optional chaining this advantage is no longer true since you can now do

map(x => x?.foo?.bar?.baz)

And it will be as safe as the pluck usage. Note that having proper TypeScript typing for pluck is quite complex and not as robust as the map usage which is a major reason to prefer the map method

jakovljevic-mladen

comment created time in 2 months

Pull request review commentReactiveX/rxjs

fix(defer) Disallow passing () => undefined to observableFactory

 it('should error if function returns undefined', () => {   const a = defer(() => undefined); // $ExpectError }); +it('should error if function returns never', () => {+  const a = defer(() => { throw new Error(); }); // $ExpectError+});

Added

kolodny

comment created time in 3 months

push eventkolodny/rxjs

Moshe Kolodny

commit sha 8f94ddf50345d1144b7614d08a43899ffc225221

moar dstlint tests

view details

push time in 3 months

push eventkolodny/rxjs

Moshe Kolodny

commit sha e2b8f2416d469294cbcee0da34cafeeb3cd8bcd2

lint

view details

push time in 3 months

push eventkolodny/rxjs

Moshe Kolodny

commit sha 9795b755c3a9992a598f09a95d738640d85045d4

Fixed tests

view details

push time in 3 months

PR opened ReactiveX/rxjs

Reviewers
fix(defer) Disallow passing () => undefined to observableFactory

fixes #5446

+7 -1

0 comment

2 changed files

pr created time in 3 months

create barnchkolodny/rxjs

branch : fix-defer

created branch time in 3 months

issue closedkolodny/immutability-helper

readme: missing brackets around array index?

should:

update(collection, {2...

be

update(collection, {[2]...

here, in the readme:

Nested collections

const collection = [1, 2, {a: [12, 17, 15]}];
const newCollection = update(collection, {2: {a: {$splice: [[1, 1, 13, 14]]}}});
// => [1, 2, {a: [12, 13, 14, 15]}]

?

closed time in 3 months

stuartcrobinson

issue commentkolodny/immutability-helper

readme: missing brackets around array index?

Either usage works, not really a typo. Open to a PR if it bothers you but closing this issue in the meantime

stuartcrobinson

comment created time in 3 months

issue closedkolodny/immutability-helper

Create deep copy without mutation

Is it possible to simply create a copy without any changes? I tried: const deepObjectCopy = update(defaultValue, {}); but with no luck

closed time in 3 months

andrew-kuzovov

issue commentfacebookexperimental/Recoil

async selectors seem busted

Hmm, so the selectors can't have an async element to them in that case. Is there any way around that? This means that if I wanted to have if/else logic in the selector, I can't make the function async before that selection. Is there some way to get both async and conditional deps?

kolodny

comment created time in 3 months

issue openedfacebookexperimental/Recoil

async selectors seem busted

https://codesandbox.io/s/recoil-counter-demo-9uir6?file=/src/App.js

Comment out the setTimeout line and it works fine

created time in 3 months

startedcdr/code-server

started time in 3 months

PR opened ReactiveX/rxjs

Reviewers
feat(groupBy): Add typeguards support for groupBy

A couple of notes here. I couldn't figure out how to test this since it doesn't work in oldish versions of TS like 2.8 which is where the dtslint tests run. If there was some way to enable/disable for TS versions that would be one solution.

Note that in the example in #5439 you need to test key === true in order to get the type checking to work for both the if and else blocks. This may be related to https://github.com/Microsoft/TypeScript/issues/26852

Another item and this is probably a TS issue is that while all 4 of the following usages work, the 5th one, using an inline type guard with no explicit arg type, doesn't work. I'm guessing there's some TS weirdness going on that's probably a bug but I can't explain what is making it behave that way

function isNumberFromAny(input: any): input is number {
  return typeof input === 'number';
}

function isNumberFromStringOrNumber(input: string | number): input is number {
  return typeof input === 'number';
}

// Works!
of('a', 1, 'b', 2).pipe(
  groupBy((x: any): x is number => typeof x === 'number'),
  mergeMap(group => {
    if (group.key === true) {
        group.subscribe(x => x.toExponential(1)); // x is number here
    } else {
        group.subscribe(x => x.toLowerCase()); // x is string here
    }
    return group;
  })
);

// Works!
of('a', 1, 'b', 2).pipe(
  groupBy((x: string | number): x is number => typeof x === 'number'),
  mergeMap(group => {
    if (group.key === true) {
        group.subscribe(x => x.toExponential(1)); // x is number here
    } else {
        group.subscribe(x => x.toLowerCase()); // x is string here
    }
    return group;
  })
);

// Works!
of('a', 1, 'b', 2).pipe(
  groupBy(isNumberFromAny),
  mergeMap(group => {
    if (group.key === true) {
        group.subscribe(x => x.toExponential(1)); // x is number here
    } else {
        group.subscribe(x => x.toLowerCase()); // x is string here
    }
    return group;
  })
);


// Works!
of('a', 1, 'b', 2).pipe(
  groupBy(isNumberFromStringOrNumber),
  mergeMap(group => {
    if (group.key === true) {
        group.subscribe(x => x.toExponential(1)); // x is number here
    } else {
        group.subscribe(x => x.toLowerCase()); // x is string here
    }
    return group;
  })
);

// THIS IS BUSTED!
of('a', 1, 'b', 2).pipe(
  groupBy((x): x is number => typeof x === 'number'),
  mergeMap(group => {
    if (group.key === true) {
        // group is GroupedObservable<true, string | number>
        group.subscribe(x => x.toExponential(1))
    } else {
        // group is GroupedObservable<false, never>
        group.subscribe(x => x.toLowerCase())
    }
    return group;
  })
);
+1 -0

0 comment

1 changed file

pr created time in 3 months

push eventkolodny/rxjs

Moshe Kolodny

commit sha 247202bb3fda27f5368e54b8791eca5569318a81

feat(groupBy): Add typeguards support for groupBy

view details

push time in 3 months

create barnchkolodny/rxjs

branch : typed-groupBy

created branch time in 3 months

started4Catalyzer/karma-jest

started time in 3 months

startedfacebook-atom/jest-electron-runner

started time in 3 months

issue commentDefinitelyTyped/DefinitelyTyped

[@types/jasmine] Jasmine toHaveBeenCalledWith matcher treats optional method arguments as required under some conditions

Note that if you supply an overload that handles all those cases it works as expected:

class Service {
    setValue(value: string, option?: undefined): void;
    setValue(value: string, option: string): void;
    setValue(value: string, option?: string): void
    setValue(value: string, option?: string): void { /* some implementation*/ }
}

const service = new Service();

expect(service.setValue).toHaveBeenCalledWith('v');
Maximaximum

comment created time in 3 months

issue commentkolodny/immutability-helper

Create deep copy without mutation

So this library attempts to reuse objects as much as possible, it will only create a shallow copy when needed due to a mutation.

var update = require("immutability-helper");

const state = {foo: 1, nested1: {a: 2}, nested2: {b: 3} };
const state2 = update(state, {nested1: {a: {$set: 4}}})

console.log('state2 nested1 same?', state.nested1 === state2.nested1); // false
console.log('state2 nested2 same?', state.nested2 === state2.nested2); // true

const state3 = update(state, {foo: {$set: 5}});

console.log('state3 nested1 same?', state.nested1 === state3.nested1); // true
console.log('state3 nested2 same?', state.nested2 === state3.nested2); // true
andrew-kuzovov

comment created time in 3 months

more