factory

Factory returning classes in TypeScript

拜拜、爱过 提交于 2021-02-18 23:47:57
问题 Wrote a library that, depending on the input data; creates classes and uses them inside a main class. To make the code more maintainable and readable, I've moved the class generation logic into a separate file that exports a factory function. Code was written in ES2015. Now I'm migrating to TypeScript. Here is a pseudo example: factory.ts export default function (foo:string) => { class A { value:string = foo + '-A'; } return { A }; }; Main.ts import factory from './factory'; export default

Factory returning classes in TypeScript

Deadly 提交于 2021-02-18 23:43:52
问题 Wrote a library that, depending on the input data; creates classes and uses them inside a main class. To make the code more maintainable and readable, I've moved the class generation logic into a separate file that exports a factory function. Code was written in ES2015. Now I'm migrating to TypeScript. Here is a pseudo example: factory.ts export default function (foo:string) => { class A { value:string = foo + '-A'; } return { A }; }; Main.ts import factory from './factory'; export default

Creating an object from a type parameter in Scala

╄→гoц情女王★ 提交于 2021-02-16 14:54:09
问题 I want to create a method that takes a type parameter, obviously with no parameters on its constructor, and returns a dummy object constructed with that constructor. Basically some kind of factory pattern. Is that even possible in Scala? Is that a good idea? Any better pattern if it is not? Is there a way to achieve this at compile-time only (i.e. without reflection)? Code example : trait Model class A extends Model class B extends Model def dummy[T <: Model] = new T // Fails compilation with

Angular 9 isssue with dynamic component load

Deadly 提交于 2021-02-11 16:56:56
问题 Dynamic components were loading absolutely fine in Angular 8. Once a component is loaded, Detach and Interest of components was also working fine. I am using ng-three-template. loadComponent(componentID: number, component: any) { this.viewContainerRef.detach(); if( this.componentFactory[componentID] == undefined ) { this.componentFactory[componentID] = this.componentFactoryResolver.resolveComponentFactory( component ); this.componentRef[componentID] = this.viewContainerRef.createComponent(

Angular 9 isssue with dynamic component load

大兔子大兔子 提交于 2021-02-11 16:55:07
问题 Dynamic components were loading absolutely fine in Angular 8. Once a component is loaded, Detach and Interest of components was also working fine. I am using ng-three-template. loadComponent(componentID: number, component: any) { this.viewContainerRef.detach(); if( this.componentFactory[componentID] == undefined ) { this.componentFactory[componentID] = this.componentFactoryResolver.resolveComponentFactory( component ); this.componentRef[componentID] = this.viewContainerRef.createComponent(

How can I use serde to deserialize into a hierarchical decentralized configuration? [duplicate]

谁说我不能喝 提交于 2021-02-10 23:26:52
问题 This question already has answers here : How can deserialization of polymorphic trait objects be added in Rust if at all? (3 answers) How do I deserialize into trait, not a concrete type? (3 answers) Closed 6 months ago . I want to have a JSON config file of the form: { "general_option_foo": true, "general_option_bar": "hello world!", "modules": [ { "name": "moduleA", "module_options" : {"optFoo":"foo"} }, { "name" : "moduleB", "module_options" : {"optBar":[3,4], "optBuzz": true} } { "name":

python class factory inherit random parent

久未见 提交于 2021-02-07 14:49:08
问题 I have some code like this: class Person(object): def drive(self, f, t): raise NotImplementedError class John(Person): def drive(self, f, t): print "John drove from %s to %s" % (f,t) class Kyle(Person): def drive(self, f, t): print "Kyle drove from %s to %s" % (f,t) class RandomPerson(Person): # instansiate either John or Kyle, and inherit it. pass class Vehicle(object): pass class Driver(Person, Vehicle): def __init__(self): # instantiate and inherit a RandomPerson somehow pass d1 = Driver()

python class factory inherit random parent

不想你离开。 提交于 2021-02-07 14:48:42
问题 I have some code like this: class Person(object): def drive(self, f, t): raise NotImplementedError class John(Person): def drive(self, f, t): print "John drove from %s to %s" % (f,t) class Kyle(Person): def drive(self, f, t): print "Kyle drove from %s to %s" % (f,t) class RandomPerson(Person): # instansiate either John or Kyle, and inherit it. pass class Vehicle(object): pass class Driver(Person, Vehicle): def __init__(self): # instantiate and inherit a RandomPerson somehow pass d1 = Driver()

How to use Faker from Factory_boy

点点圈 提交于 2021-02-04 14:25:28
问题 Factory_boy uses fake-factory (Faker) to generate random values, I would like to generate some random values in my Django tests using Faker directly. Factory_boy docs suggests using factory.Faker and its provider as : class RandomUserFactory(factory.Factory): class Meta: model = models.User first_name = factory.Faker('first_name') But this isn't generating any name: >>> import factory >>> factory.Faker('name') <factory.faker.Faker object at 0x7f1807bf5278> >>> type(factory.Faker('name'))

How with $faker->word get unique value?

微笑、不失礼 提交于 2021-01-28 07:44:06
问题 In laravel 5.8 app I make tests and adding new user for any tests I encountered that line $loggedUser= factory(User::class)->create(); raise error : Doctrine\DBAL\Driver\PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Username pariatur' for key 'users_username_unique' with factory defined : $factory->define(App\User::class, function (Faker $faker) { $username= 'Username ' . $faker->word; return [ 'username' => $username, I do not clear database, but how to