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

relegater

v1.0.2

Published

provide function which delegates a property access or method call to other object like 'delegate' in Ruby on Rails.

Downloads

9

Readme

relegater

Build Status Coverage Status

provide functions in order to delegate a property access or method call for base object to other.

Interfaces of the functions imitate delegate method in Ruby on Rails.

example

import { delegate, $delegate } from 'relegater';

const baseObj = {
  a: 1, b: 'b'
};
const delegated = {
  c: () => 'c',
  d: {
    e: true
  }
};

// delegate() create new object.
// no update to base object exist.
var result = delegate(baseObj).to(delegated, 'c', 'd').self;

result.a // 1
result.b // 'b'
result.c() // 'c'
result.d.e // true

baseObj.a // 1
baseObj.b // 'b'
baseObj.c // undefined
baseObj.d // undefined

// $delegate() modify base object destructively.
$delegate(baseObj).to(delegated, 'c', 'd');

baseObj.a // 1
baseObj.b // 'b'
baseObj.c() // 'c'
baseObj.d.e // true

baseObj is a object which receive actually property accesses or method calls.

when you want to delegate reference for baseObj to other, you should pass baseObj to delegate() or $delegate().

delegate()

delegate() create a new object which extends baseObj.

this function don't modify baseObj, so you use the created object instead of baseObj.

you can get the object from delegate({}).self.

$delegate()

$delegate() modify baseObj directly and destructively, but not modify prototype of baseObj.

how to delegate

delegate()/$delegate() return object which has following property.

  • to(delegated, prop1, prop2, ... propX)

    this method return a new object which has same interface. this method can chain. when a property is specified twice in the method chain, later is preferred.

    delegated is a object which baseObj delegate some property accesses or method calls to.

    • delegated must be object. if this is not object, runtime error raise.

    • prop1~X is variable arguments. each prop is string which presents property name in delegated;

      if propX does not exist in delegated, it is ignored.

  • self this property exist only when you use delegate().

    this object base on baseObj and has all properties which are specified by to().

License

MIT License