From 709258bfa455b35d2f311f65abd77d872ab0e7c9 Mon Sep 17 00:00:00 2001 From: Sebastian Kappen Date: Wed, 12 Dec 2018 09:44:00 +0100 Subject: [PATCH 1/2] Fix ObservableComponent::useEvent ignoring seed ObservableComponent::useEvent checked whether more than one argument was supplied (correct), but used the 3rd argument as a seed value instead. That argument is always undefined when using Refract according to the docs. This bug was introduced with commit d24f0f099b2. This commit changes the function signature back to the original one of using 2 args, one being optional. The check for the actual argument count is then done using the arguments object. --- base/react/observable.ts | 6 ++---- base/react/observable_callbag.ts | 6 ++---- base/react/observable_most.ts | 6 ++---- base/react/observable_xstream.ts | 6 ++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/base/react/observable.ts b/base/react/observable.ts index e58627bd..c8702326 100644 --- a/base/react/observable.ts +++ b/base/react/observable.ts @@ -87,10 +87,8 @@ const getComponentBase = ( }) ) - const useEvent = (...args) => { - const eventName: string = args[0] - const hasSeedValue = args.length > 1 - const seedValue = args[2] + const useEvent = (eventName: string, seedValue?: any) => { + const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName) diff --git a/base/react/observable_callbag.ts b/base/react/observable_callbag.ts index 4a1e59fa..8981f139 100644 --- a/base/react/observable_callbag.ts +++ b/base/react/observable_callbag.ts @@ -90,10 +90,8 @@ const getComponentBase = ( }) ) - const useEvent = (...args) => { - const eventName: string = args[0] - const hasSeedValue = args.length > 1 - const seedValue = args[2] + const useEvent = (eventName: string, seedValue?: any) => { + const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName) diff --git a/base/react/observable_most.ts b/base/react/observable_most.ts index 051d0287..687f13fd 100644 --- a/base/react/observable_most.ts +++ b/base/react/observable_most.ts @@ -75,10 +75,8 @@ const getComponentBase = ( return valueTransformer ? valueTransformer(value) : value }) - const useEvent = (...args) => { - const eventName: string = args[0] - const hasSeedValue = args.length > 1 - const seedValue = args[2] + const useEvent = (eventName: string, seedValue?: any) => { + const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName) diff --git a/base/react/observable_xstream.ts b/base/react/observable_xstream.ts index 737fa2c2..9fc4ce31 100644 --- a/base/react/observable_xstream.ts +++ b/base/react/observable_xstream.ts @@ -73,10 +73,8 @@ const getComponentBase = ( return valueTransformer ? valueTransformer(value) : value }) - const useEvent = (...args) => { - const eventName: string = args[0] - const hasSeedValue = args.length > 1 - const seedValue = args[2] + const useEvent = (eventName: string, seedValue?: any) => { + const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName) From 3e6eb37b8c7a7c5fc20fc801d854f06d90fae823 Mon Sep 17 00:00:00 2001 From: Sebastian Kappen Date: Wed, 12 Dec 2018 09:57:51 +0100 Subject: [PATCH 2/2] Make useEvent a regular function The arguments object cannot be used in arrow functions. useEvent doesn't have to be an arrow function, so we define it as a regular function instead. --- base/react/observable.ts | 2 +- base/react/observable_callbag.ts | 2 +- base/react/observable_most.ts | 2 +- base/react/observable_xstream.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/base/react/observable.ts b/base/react/observable.ts index c8702326..404494c7 100644 --- a/base/react/observable.ts +++ b/base/react/observable.ts @@ -87,7 +87,7 @@ const getComponentBase = ( }) ) - const useEvent = (eventName: string, seedValue?: any) => { + function useEvent(eventName: string, seedValue?: any) { const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName) diff --git a/base/react/observable_callbag.ts b/base/react/observable_callbag.ts index 8981f139..d5853054 100644 --- a/base/react/observable_callbag.ts +++ b/base/react/observable_callbag.ts @@ -90,7 +90,7 @@ const getComponentBase = ( }) ) - const useEvent = (eventName: string, seedValue?: any) => { + function useEvent(eventName: string, seedValue?: any) { const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName) diff --git a/base/react/observable_most.ts b/base/react/observable_most.ts index 687f13fd..68cbac03 100644 --- a/base/react/observable_most.ts +++ b/base/react/observable_most.ts @@ -75,7 +75,7 @@ const getComponentBase = ( return valueTransformer ? valueTransformer(value) : value }) - const useEvent = (eventName: string, seedValue?: any) => { + function useEvent(eventName: string, seedValue?: any) { const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName) diff --git a/base/react/observable_xstream.ts b/base/react/observable_xstream.ts index 9fc4ce31..57bd79ab 100644 --- a/base/react/observable_xstream.ts +++ b/base/react/observable_xstream.ts @@ -73,7 +73,7 @@ const getComponentBase = ( return valueTransformer ? valueTransformer(value) : value }) - const useEvent = (eventName: string, seedValue?: any) => { + function useEvent(eventName: string, seedValue?: any) { const hasSeedValue = arguments.length > 1 const events$ = fromEvent(eventName) const pushEventValue = pushEvent(eventName)