Git Product home page Git Product logo

constitute's People

Contributors

justmoon avatar vhpoet 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

constitute's Issues

Is it possible to mock it?

I apologize for my stupid question beforehand.

I was trying to mock constitute, using
jest.mock( 'constitute' )

but it seems to throw me an error
TypeError: _dec is not a function

Is there a way where I can mock constitute function, properly?

Injecting libraries

Hello,

I think it would be great to support libraries on the container that don't need to be instantiated and can be referenced by using the library itself. Currently I have to do this:

libraries.js:

import $ from 'jquery';
import { Value } from 'constitute';

export const jQuery = new Value($);

Then, I have to find wherever the libraries.js file is located relative to my current script and pass in the correct value.

test.js:

import constitute, { Dependencies, Value } from 'constitute';
import {jQuery} from '../some/path/to/lib/libraries.js';

@Dependencies(jQuery)
class Test {
   constructor($) {
    this.$ = $;
   }
}

While this isn't the worst thing in the world, I think it would be nice to be able to reference jQuery as a dependency and the system knows to treat it as a Value (aka library in my case).

config.js:

import _ from 'lodash';
import $ from 'jquery';
import constitute from 'constitute';

// configuration
constitute.addValues([_, $, ...etc]);

example.js:

import _ from 'lodash';
import $ from 'jquery';
import constitute, { Dependencies } from 'constitute';

@Dependencies(_, jQuery)
class Test {
   constructor(_, $) {
    this._ = _;
    this.$ = $;
   }
}

I think this way we could continue to import libraries as we normally do while letting constitute replace it where necessary if we overwrite it. I'm not sure how this works under the hood to know if it's even possible but I think it would make things a little more maintainable. Or is there perhaps a better way mockup when I did in the first scenario?

Thanks!

Constitute is creating new objects rather than referencing existing

Consider the following code example:

class Foo {

  bar = 'should be overwritten';

}

let foo1 = constitute(Foo);
let foo2 = constitute(Foo);

foo1.bar = 'i have the new value!';

console.log('foo 1:');
console.log(foo1.bar);

console.log('foo 2:');
console.log(foo2.bar);

In this case, constitute should have cached the instance of Foo when setting foo1. Then foo2 should therefor use the same instance as foo1;

However this is the console output I received:

foo 1:
> i have the new value!
foo 2:
> should be overwritten

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.