GithubHelp home page GithubHelp logo

builder-pattern's People

Contributors

dependabot[bot] avatar hajoahomantila avatar mbarnathan avatar omeha2 avatar vincent-pang 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

builder-pattern's Issues

[Feature Request] Enabling override of builder props

Hi,
In our projects we usually use builders like this for usage in tests:

contact-builder.ts

export const aContact = () => Builder<Contact>().fullName(chance.string()).phoneNumber(chance.phone()).build();

This is done so that not every test needs to know "Builder" and "Contact" and "" to function.

The thing is that many tests, want to add an override on the default properties. So we end up writing the builders like so:

export const aContact = (props?: Partial<Contact>) => ({
  ...Builder<Contact>().fullName(chance.string()).phoneNumber(chance.phone()).build(),
  ...props,
});

Feature Request
Being able to call an "override" method before calling build (which is like calling the constructor):

export const aContact = (props?: Partial<Contact>) =>
  Builder<Contact>()
    .fullName(chance.string())
    .phoneNumber(chance.phone())
    .override(props)
    .build();

Or simply use the build method:

export const aContact = (props?: Partial<Contact>) =>
  Builder<Contact>()
    .fullName(chance.string())
    .phoneNumber(chance.phone())
    .build(props);

I'm willing to donate the code, just want to know the feature will be accepted.

Performance of the lib compared to vanilla Javascript

Vincent Peng, your open source lib for the builder pattern is a very good idea, thanks.

I have a question about performance.
I sometimes read that the ES6 proxies are not very fast and performant compared to the vanilla javascript.

If we use your lib, the performance are good ?
Can you give me an opinion about that please ?

Sorry to open an issue for that, but i wanted to send you a private message, but i didn't find your email address.

will broke annotation

Thank your for developing this awesome library!
I use it to build domain object, but it will affect the annotations. the annotations in all field will lost

Not able to use builder to set optional field to undefined

export interface Data {
    title: string;
    note?: string;
}

const a = Builder<Data>().title("test").note("note").build();
const b = Builder(a).note(undefined).build();  /// I am getting compilation error. Argument of type 'undefined' is not assignable to parameter of type 'string'

Even I declared the "note" as optional, the builder still doesn't allow set undefined to it. Could you tell me how to remove existing value using this builder library?

Support for collections

Exposing additional methods for collections would be helpful, for example in the Type class at present we have setter for name, properties and it would be useful if we can have addItem(key, property);

I tried adding a manual method inside Type class but it wasn't able to accept a object built out of builder lib. Found it strange.

export class Type {
    
    name: string;
    properties: Map<String, Property> = new Map<String, Property>();
export class Property {
    name: string;
}

Does this library support class method?

Hi. Thanks for this great library.

I've been using it for my side project, and encountered a problem.

My class looks like:

export class MyClass {
  id:number;
  public method(){};
}

I created a class instance by using builder as below:

const myClass: MyClass =
  Builder<MyClass>()
        .id(1)
        .build();

I expected the instance would have the class method but the object does not have any method.

Does build method only support field properties, not the method?

Regards,

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.