npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rx-with-event-handler-props

v1.4.1

Published

rxjs-based component behaviour for lifting a component-from-stream that adds an event-handler property and injects an event property when that handler is called with a payload

Downloads

25

Readme

rx-with-event-handler-props

NPM

rxjs-based component behaviour (reactive props stream operator) for lifting a component-from-stream that adds an event-handler property and injects an event property when that handler is called with a payload.

API

for a detailed specification of this API, run the unit tests in your browser.

example usage

const behaviour = compose(
  // ... behaviours that may depend on the injected { id: 'click' } EventProp
  withEventHandler('click'),
  // ... other behaviours that do not require access to the EventHandlerProps
)
// SFC that uses the handler from the EventHandlerProp
const Clickable = ({ onClick /*, other props */ }) => (
  <div onClick={onClick}>
  <!-- ... -->
  </div>
)
// ...
export componentFromStream(Clickable, behaviour)

by default, when the handler from the EventHanderProp is called, its payload is mapped to an EventProp property on the object emitted by the output stream:

(payload: E, id: string) => ({ event: { id, payload } })

alternatively, withEventHandler may be called with a custom event-to-event-prop mapping function that maps the handler's payload to a custom property on the output object. this may be used for example to generate an 'action' property instead of EventProp:

const createAction = type => payload => ({ action: { type, payload } })
const behaviour = compose(
  // ... behaviours that handle the 'action' property, e.g. with reducers
  withEventHandler(createAction('INCREMENT'))('click')
  // ...
)
// ...

type definitions

declare function withEventHandlerProps <E>(
  id: string
): EventHandlerPropsOperator<E>
declare function withEventHandlerProps <E>(
  /* project = (payload: E, id: string) => ({ event: { id, payload } }) */
): (id: string) => EventHandlerPropsOperator<E>
declare function withEventHandlerProps <E,L>(
  project: EventMapper<E,L>
): (id: string) => EventHandlerPropsOperator<E,L>

declare function hasEventHandler(id: string): (p: any) => boolean
declare function toHandlerKey (id: string): string
declare function hasEvent(id: string): (p: any) => boolean

type EventHandlerPropsOperator<E,L=EventProp<E>> =
<P>(props$: Observable<P>) => Observable<P&EventHandlerProps<E,L>>

type EventHandlerProps<E,L> = EventHandlerProp<E> & Partial<L>

interface EventHandlerProp<E> {
  [onId: string]: (event: E) => void
}

interface EventProp<E> {
  event: { id: string, payload: E|P, event?: E } // event? from Inferno LinkEvent
}

interface EventMapper<E,L=EventProp<E>> {
  (event: E, id?: string): L
  <P>(payload: P, event: E, id?: string): L // Inferno LinkEvent signature
}

in addition to the withEventHandlerProps default export, this module also exports three utility functions: hasEventHandler, hasEvent and toHandlerKey. the latter returns the props key of the handler function.

TypeScript

although this library is written in TypeScript, it may also be imported into plain JavaScript code: modern code editors will still benefit from the available type definition, e.g. for helpful code completion.

License

Copyright 2018 Stéphane M. Catala

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and Limitations under the License.