Git Product home page Git Product logo

ioc's People

Contributors

greenkeeper[bot] avatar hbroer avatar ksaxberg avatar lorefnon avatar vic1707 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

ioc's Issues

possibility to hook into `container.get()` (plugin)

a simple plugin functionality could fix some needs to get rid of some boilerplate code if for example a service should trigger a listener, subscribe and unsubscribe automatically on mount and unmount of components. Plugins are more versatile and easier to adapt than application specific code.

This is a replacement for #22

Examples have bugs

The README.md has to be checked. There is at least one error.

export const TYPE = {
    "MyService" = Symbol("MyService"),
    "MyOtherService" = Symbol("MyOtherService"),
};

should be

export const TYPE = {
    MyService: Symbol("MyService"),
    MyOtherService: Symbol("MyOtherService"),
};

An in-range update of @typescript-eslint/parser is breaking the build 🚨

The devDependency @typescript-eslint/parser was updated from 2.7.0 to 2.8.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/parser is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v2.8.0

2.8.0 (2019-11-18)

Bug Fixes

  • eslint-plugin: [camelcase] handle optional member expr (#1204) (9c8203f)
  • eslint-plugin: [indent] fix decorator type (#1189) (e2008e3)
  • eslint-plugin: [indent] handle empty generic declarations (#1211) (9aee06c)
  • eslint-plugin: [no-type-alias] handle constructor aliases (#1198) (1bb4d63)
  • eslint-plugin: [no-unnec-type-arg] throwing on call/new expr (#1217) (42a48de)
  • eslint-plugin: [no-unnecessary-cond] fix naked type param (#1207) (4fac6c5)
  • eslint-plugin: [nuta] correctly handle null/undefined separation (#1201) (9829dd3)
  • eslint-plugin: [require-await] better handle nesting (#1193) (eb83af1)
  • eslint-plugin: [unified-signatures] crash: cannot read pro… (#1096) (d1de3a7)
  • eslint-plugin: disable base no-unused-expressions in all config (ecb3f4e)
  • typescript-estree: correctly account for trailing slash in… (#1205) (ba89168)
  • typescript-estree: options range loc being always true (#704) (db1aa18)

Features

  • eslint-plugin: [no-type-alias] handle conditional types (#953) (259ff20)
  • eslint-plugin: add rule restrict-template-expressions (#850) (46b58b4)
  • eslint-plugin: add space-before-function-paren [extension] (#924) (d8b07a7)
  • eslint-plugin: added new rule no-dynamic-delete (#565) (864c811)
  • eslint-plugin: added new rule no-untyped-public-signature (#801) (c5835f3)
Commits

The new version differs by 20 commits.

  • a9117f5 chore: publish v2.8.0
  • 46b58b4 feat(eslint-plugin): add rule restrict-template-expressions (#850)
  • 42a48de fix(eslint-plugin): [no-unnec-type-arg] throwing on call/new expr (#1217)
  • ba89168 fix(typescript-estree): correctly account for trailing slash in… (#1205)
  • eb83af1 fix(eslint-plugin): [require-await] better handle nesting (#1193)
  • 9829dd3 fix(eslint-plugin): [nuta] correctly handle null/undefined separation (#1201)
  • d1de3a7 fix(eslint-plugin): [unified-signatures] crash: cannot read pro… (#1096)
  • 9aee06c fix(eslint-plugin): [indent] handle empty generic declarations (#1211)
  • 74192f8 chore: bump dependencies (#1208)
  • e2008e3 fix(eslint-plugin): [indent] fix decorator type (#1189)
  • 4fac6c5 fix(eslint-plugin): [no-unnecessary-cond] fix naked type param (#1207)
  • 259ff20 feat(eslint-plugin): [no-type-alias] handle conditional types (#953)
  • 9c8203f fix(eslint-plugin): [camelcase] handle optional member expr (#1204)
  • d8b07a7 feat(eslint-plugin): add space-before-function-paren [extension] (#924)
  • ca41dcf docs(eslint-plugin): brace-style as a replacement for one-line (#1202)

There are 20 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Testing & Code Reviews

I could need some help with testing and some people doing code review of my own work. Feel free to open Issue, make pull requests or just comment here. :)

An in-range update of eslint-plugin-jest is breaking the build 🚨

The devDependency eslint-plugin-jest was updated from 22.9.0 to 22.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v22.10.0

22.10.0 (2019-07-17)

Features

Commits

The new version differs by 7 commits.

  • 28bd1dc feat(rules): adds no-if rule (#293)
  • 7ebdc0e chore: enforce import destructure order
  • 31c7cef chore: convert to import/export (#302)
  • 9f858cb chore: delete tests instead of ignoring them with babel
  • c595ba0 chore: do not include tests in published tarball
  • 4b4eb78 chore: fix lint error in md file
  • d3ea720 chore(docs): fix typo (#304)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of eslint-plugin-jest is breaking the build 🚨

The devDependency eslint-plugin-jest was updated from 22.6.1 to 22.6.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v22.6.2

22.6.2 (2019-05-22)

Bug Fixes

  • move @typescript-eslint/experimental-utils to dependencies (#267) (331457d)
Commits

The new version differs by 1 commits.

  • 331457d fix: move @typescript-eslint/experimental-utils to dependencies (#267)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @types/jest is breaking the build 🚨

The devDependency @types/jest was updated from 24.0.19 to 24.0.20.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Inline Documentation

People suggested to add some inline documentation because they have problems to understand how the library works. This should be fixed.

1.0.0 Release

  • Check Documentation if everything is correct
  • Remove the beta "unstable" info from documentation
  • Set package.json version to 1.0.0
  • Tag and deploy to npm

Performance Enhancement

  • get the dependency from the container only once
  • listen on rebinds to delete the cached dependency so it will reresolved on next get

Cache None-Singletons

Is your feature request something you would just nice to see implemented?
It would be nice if a dependency which got injected will not resolve on every call on the propery which resolves the dependency. It would be nice too if this behavior can be configured.

Describe the solution you'd like
I am not shure which solution i wuld prefer. For myself i normaly use dependencies in singelton scope. But sometimes it could be usefull to resolve a dependency only once per instance. And this feature will improof performance too if caching is the default behavior.

Question

Which implementation whould you prefer? Or keep the current state? Or any other suggestion?

Release 1.0.0-beta.0

  • deploy with travis to npmjs no automatic deployment at the moment
  • Check example implementation
  • Update documentation

An in-range update of @typescript-eslint/eslint-plugin is breaking the build 🚨

The devDependency @typescript-eslint/eslint-plugin was updated from 1.9.0 to 1.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/eslint-plugin is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Inject a service that requires constructor arguments ?

Id like to be able to inject a class that requires arguments for it's constructor which would give more flexibility for some use cases.

Describe the solution you'd like
I think a rework of the Factory type could do the trick, for now it doesn't accept any parameters 🤔
the idea, if possible, would be to usesomething like this
container.bind(<symbol>).toFactory( (...args: InjectedConstructorArgs) => new Injected(...args)) )
and then
resolveContainer(<symbol>)(...args)

Describe alternatives you've considered
put the constructor logic in another function that is called manually after injection

wire/inject/resolve strictly binds service to specific container

Hi, i use @owja/ioc in Node.js app.

In my app i have a service (for example named MyService) that has one dependency.

I use wire function for define dependency.

In my case i have two containers in two apps and i want to use MyService in both of containers

But the wire function is created for a specific container strictly binds each service to the container.

In my case i act like this:

const createMyService = wire => class MyService {
  constructor () {
    wire(this, 'myDependency', TYPE.myDependency)
  }
};

But it looks more like a trick.

How can i properly create service for use it in any container?

An in-range update of eslint-plugin-jest is breaking the build 🚨

The devDependency eslint-plugin-jest was updated from 22.5.1 to 22.6.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v22.6.0

22.6.0 (2019-05-22)

Features

Commits

The new version differs by 9 commits.

  • 14d83ef feat(rules): add no-commented-out rule (#262)
  • 83ff198 chore: migrate no-jest-import to typescript (#259)
  • 718c08c chore: upgrade @typescript-eslint
  • ca2aa27 chore: port lowercase-name to TypeScript (#258)
  • 3df0058 chore(ci): run danger with lts version of node
  • 48e3a59 chore: precompile with babel (#257)
  • 8670804 chore: bump deps
  • 05eb11a chore: fix lint error
  • dff6446 docs: link to eslint-plugin-jest-formatting

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Singelton Scope

Make it possible to bind in in singleton scope.

  • .to().inSingeltonScope()
  • .toFactory().inSingeltonScope()

.toValue() is not affected.

Async construction?

Hey, I might need to download a bundle containing a service when resolving it so I need a way to .get asynchronously and have async factories (like in InversifyJS for example).

Alternatively if plugins could return a Promise I guess that would also work for this use case.

`toValue` consider function given as a factory.

Describe the bug
The Container.bind(...).toValue(...) consider the a given function as a fatory.

To Reproduce

import { Container, token } from "@owja/ioc"
const TYPE = {
  myType: token("MyType")
}
const container = new Container()
container.bind(TYPE.myType).toValue((text) => {
  if (text === undefined) console.log("You cannot give undefined.")
  else console.log(text)
})
const myFunc = container.get(TYPE.myType)
myFunc("hello, world!")

the console output is

You cannot give undefined.
file:///test.js:11
myFunc("hello, world!")
^

TypeError: myFunc is not a function

Expected behavior
I want to bind a Getter function, such as (options) => create(options) with toValue, however, the container considered it as a factory and tried to call it and retrieved the return value.

I don't think toValue() should detect its type under the hood, which made me confused.
Instead, toFactory() is more suitable for this.

Environment (please complete the following information):

  • typescript^4.9.5
  • Node v16.18.0
  • ^2.0.0-alpha.6

Additional context
The workaround is to wrap the function with a new function.

container.bind(TYPE.myType).toValue(() => (text) => {
  if (text === undefined) console.log("You cannot give undefined.")
  else console.log(text)
})

But it makes the typing sucks in typescript.
Because the token should be token<()=>(text:string)=>void>("MyType"), then the return value from container.get(...) is typed by ()=>(text:string)=>void but (text:string)=>void is actually expected.

Idea for the docs?

This is how I personally like to use this library in my project:

import {Container} from "@owja/ioc";
const container = new Container();

const BAR = Symbol.for("bar")
const FOO = Symbol.for("foo")

interface Foo {
  doThing(): void
  tellBarToDoThing(): void 
}

class AppFoo implements Foo {
  constructor(private bar: Bar = container.get(BAR)) {}

  doThing(): void {
    console.log('foo do thing')
  }

  tellBarToDoThing() {
    this.bar.doThing()
  }
}

container.bind<Foo>(FOO).to(AppFoo)
interface Bar {
  doThing(): void 
  tellFooToDoThing(): void
}

class AppBar implements Bar {
  constructor(private foo: Foo = container.get(FOO)) {}
  doThing() {
    console.log('bar do thing')
  }

  tellFooToDoThing() {
    this.foo.doThing()
  }
}

// You don't need to use `toFactory()` below, but here just for example sake. 
container.bind<Bar>(BAR).toFactory(() => { return new AppBar() }).inSingletonScope() 

let foo: Foo = container.get(FOO)
foo.doThing()

let bar: Bar = container.get(BAR)
bar.doThing()

The code to look at here is the constructors of the classes. This is how I like to resolve the dependencies for my classes instead of wire() or resolve() that the readme suggests.

Wanted to see what you thought. Do you see anything wrong with this? Do you see it as a value add to add this technique to the readme as another option to resolving dependencies?

Maybe container has an implicit behavior

Hi, first of all thanks for pretty good library.

I noticed that container can have an implicit behaviour.

According to api, i can bind service to symbol and save options to the variable.
Later I can start get services from the container by symbol.
But after that I can use options to change type of service by options.toSingletonScope()

After changing service type I will receive only one instance.

I don't know, maybe it is a regular behaviour but it can confuse the developer.

Maybe I'm wrong and this behaviour implies that at the time of binding, the developer may not know what the service should be.

P.S. Sorry for bug label...

An in-range update of @typescript-eslint/eslint-plugin is breaking the build 🚨

The devDependency @typescript-eslint/eslint-plugin was updated from 2.10.0 to 2.11.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/eslint-plugin is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v2.11.0

2.11.0 (2019-12-09)

Bug Fixes

  • eslint-plugin: [brace-style] handle enum declarations (#1281) (3ddf1a2)

Features

  • eslint-plugin: [member-ordering] add index signature (#1190) (b5a52a3)
Commits

The new version differs by 6 commits.

  • 9f76095 chore: publish v2.11.0
  • 324f155 docs(eslint-plugin): ROADMAP note some jsdoc rules (#1319)
  • 3ddf1a2 fix(eslint-plugin): [brace-style] handle enum declarations (#1281)
  • b5a52a3 feat(eslint-plugin): [member-ordering] add index signature (#1190)
  • 39f654b test(eslint-plugin): [unified-signatures] add tests for #740 (#1074)
  • 5362561 docs(eslint-plugin): typo in space-before-function-paren docs (#1297)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @typescript-eslint/parser is breaking the build 🚨

The devDependency @typescript-eslint/parser was updated from 1.9.0 to 1.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@typescript-eslint/parser is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Dynamically reload injection

Hello,

First of all, I want to thank you for your awesome project !

I'm currently using the version 2.0.0-alpha.3 on a REACT game project.

For my project I would like to be able to test multiple JSX versions of the same component on the fly.

I'd like for all my components to come with a SVG version, a WebGL and canvas one.
For this issue I assumed I have two redering method svg and svg2 (canvas and webGL cause issues due to useEffect being used).

I have the logic for my component in a vanilla class and injected render method based on a token.

I think (and hope) the code is kinda self explanatory.

Here are the files I use for now

  • container.ts containing tokens for the rendering methods.
export type renderingMethods = 'canvas' | 'svg' | 'svg2' | 'webGL';

const container = new Container();
export const resolve = createResolve(container);
export const get = container.get;

export const RENDERERS: { [K in renderingMethods]: Token<FunctionComponent<Props>> } = {
  canvas: token('canvas'),
  svg: token('svg'),
  svg2: token('svg2'),
  webGL: token('webGL')
};

container.bind(RENDERERS.canvas).toValue(BoardCanvas);
container.bind(RENDERERS.svg).toValue(BoardSVG);
container.bind(RENDERERS.svg2).toValue(BoardSVG2);
container.bind(RENDERERS.webGL).toValue(BoardWebGL);
  • App.tsx with a select in the header to choose the rendering method.
function App() {
  const board = new Board({ x: 200, y: 200 });
  const [renderer, setRenderer] = useState<renderingMethods>('svg');

  return (
    <>
      <header>
        <label>
          Rendering Method
          <br />
          <select value={renderer} onChange={({ target: { value } }) => setRenderer(value as renderingMethods)}>
            <option value="canvas">Canvas</option>
            <option value="svg">SVG</option>
            <option value="svg2">SVG2</option>
            <option value="webGL">WebGL</option>
          </select>
        </label>
        {renderer}
      </header>
      <div className="App">{board.render(renderer)}</div>
    </>
  );
}
  • Board.ts
export class Board implements board {
  bounds: BoardRanges;

  constructor(bounds: BoardRanges) {
    this.bounds = {
      x: Math.abs(bounds.x),
      y: Math.abs(bounds.y)
    };
  }

  readonly render = (renderer: renderingMethods) => resolve(RENDERERS[renderer])()({ bounds: this.bounds });
}
  • the svg renderer
export const BoardSVG: FunctionComponent<Props> = ({ bounds }: Props) => {
  console.log('using board svg');
  return (
    <svg width={bounds.x} height={bounds.y} className="game-board">
      <g transform={`matrix(1 0 0 -1 ${bounds.x / 2} ${bounds.y / 2})`}>
        <line x1={-bounds.x / 2} x2={bounds.x / 2} strokeWidth="1px" stroke="#000" />
        <line y1={-bounds.y / 2} y2={bounds.y / 2} strokeWidth="1px" stroke="#000" />
      </g>
    </svg>
  );
};
  • the svg2 renderer
export const BoardSVG2: FunctionComponent<Props> = ({ bounds }: Props) => {
  console.log('using board svg2');
  return (
    <svg width={bounds.x} height={bounds.y} className="game-board">
      <g transform={`matrix(1 0 0 -1 ${bounds.x / 2} ${bounds.y / 2})`}>
        <line x1={-bounds.x / 2} x2={bounds.x / 2} strokeWidth="1px" stroke="#333" />
        <line y1={-bounds.y / 2} y2={bounds.y / 2} strokeWidth="1px" stroke="#333" />
      </g>
    </svg>
  );
};

the UI/injection doesn't seem to reload as it always giving me the console.log('using board svg'); output.

I'm not really sure if it's a problem with the lib or with me not doing things correctly

Example Repository

create a new repository with examples

  • ...for javascript
  • ...for typescript

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.