Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Suggestion #9

Open
robblovell opened this issue Feb 3, 2023 · 0 comments
Open

Documentation Suggestion #9

robblovell opened this issue Feb 3, 2023 · 0 comments

Comments

@robblovell
Copy link

robblovell commented Feb 3, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant