GithubHelp home page GithubHelp logo

proxymise's People

Contributors

kozhevnikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proxymise's Issues

UMD

to use the library in browser you need to use:

<script>var module = {}</script>

it would be nice if there was UMD module definition.

proxymise not working with Knex queries

proxymise is great, thank you!

Unfortunately I've just discovered that it's not working with Knex.js queries. Here's an example which demonstrates the problem.

// $ npm install knex sqlite3 proxymise
import Knex from 'knex'
import proxymise from 'proxymise';

async function main() {
  // create Knex connection
  const knex = Knex({
    client: 'sqlite3',
    useNullAsDefault: true,
    connection: {
      filename: ':memory:',
    },
  });

  // create a users table
  await knex.raw(
    'CREATE TABLE users ( ' +
    '  id INTEGER PRIMARY KEY ASC, ' +
    '  name TEXT ' +
    ')'
  );

  // insert a row
  await knex('users').insert({
    name: 'kozhevnikov'
  });

  // knex example without proxymise()
  const row = await knex('users').select('id', 'name').where({ name: 'kozhevnikov' }).first();
  const name = row.name;
  console.log('EXPECT name: ', name);

  // works if knex method are inside proxymise()
  try {
    const prxm1 = proxymise(
      knex('users')
        .select('id', 'name')
        .where({ name: 'kozhevnikov' })
        .first()
    );
    const name1 = await prxm1.name;
    console.log('PASSED name1:', name1);
  }
  catch(error) {
    console.log('FAILED name1:', error);
  }

  // doesn't work when knex methods are outside proxymise()
  try {
    const prxm2 = proxymise(
      knex('users')
    );
    const name2 = await prxm2
      .select('id', 'name')
      .where({ name: 'kozhevnikov' })
      .first()
      .name;
    console.log('PASSED name2:', name2);
  }
  catch(error) {
    console.log('FAILED name2:', error);
  }

  knex.destroy();
}

main();

Output:

EXPECT name:  kozhevnikov
PASSED name1: kozhevnikov
FAILED name2: TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
    at .../[email protected]/node_modules/proxymise/index.js:27:53
    at async main (file:///.../proxymise-knex-bug.js:53:19)

Documentation Suggestion

Documentation suggestion:

It would be good to include a simple implementation that isn't already built somewhere as an example for people who want to write a fluent client to do something. The code for Fetch, AWS, and Selenium isn't easy to understand!

This would be a bit of a different use case. The client itself would leverage proxymise to implement fluent async methods without the developer using the client having to leverage proxymise. It's already built into the client.

Here's my example: (I realize the methods below aren't async, but they do return promises... It's just a dumb example of the syntax required to build a fluent client that uses proxymise to have async methods).

person.js:

import proxymise from "proxymise";

export class PersonBuilder {
    constructor() {
        this.person = {};
        return proxymise(this)
    }
    async withName(name) {
        this.person.name = name;
        return this;
    }
    async withAge(age) {
        this.person.age = age;
        return this;
    }
    async build() {
        return this.person;
    }
}

app.js

import { PersonBuilder } from "./person.js"

const personBuilder = new PersonBuilder()
const person = await personBuilder
    .withName("Daffodil")
    .withAge(25)
    .build();
console.log(person);

(call out to: https://dev.to/nas5w/using-the-fluent-interface-pattern-to-create-javascript-objects-2p1n)

Performance penalty info

Proxies are still pretty slooooow. It would be nice to see how much of performance we're sacrificing by using this approach. Please add some benchmarks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.