Coder Social home page Coder Social logo

miconjs's Introduction

Dependency injector, assembles application.

Registering, getting and setting components.

app.register 'component', -> 'some component'
console.log app.component
# => some component

app.component = 'another component'
console.log app.component
# => another component

Dependencies can be specified implicitly.

app.register 'a', ->
  console.log 'initializing a'
  'a'
app.register 'b', ->
  console.log 'initializing b'
  "#{app.a} b"

console.log app.b
# => initializing b
# => initializing a
# => a b

Or explicitly. The only difference with implicit approach is that explicit declaration will resolve circular dependencies (implicit approach will fail).

app.register 'a', ->
  console.log 'initializing a'
  'a'
app.register 'b', dependencies: ['a'], ->
  console.log 'initializing b'
  "#{app.a} b"

console.log app.b
# => initializing a
# => initializing b
# => a b

Component lifecycle callbacks.

app.register 'component', ->
  console.log 'initialization'
  'some component'
app.before 'component', -> console.log 'before initialization'
app.after 'component', -> console.log 'after initialization'

app.component
# => before initialization
# => initialization
# => after initialization

Scopes.

app.register 'params', scope: 'request', -> {}

startFiberSomehow ->
  app.scope 'request', ->
    app.params.key = 'some value'
    console.log app.params
    # => {key: 'some value'}

Scope callbacks.

app.beforeScope 'request', -> console.log 'before'
app.afterScope 'request', -> console.log 'after'

startFiberSomehow ->
  app.scope 'request', ->
  # => before
  # => after

Require files in directory, provide watch: true option to watch for changes and reload.

# /app/controllers/SomeController.coffee
# app.SomeController = 'some controller'

app.requireDirectory '/absolutePath/app/controllers', watch: true

console.log app.SomeController
# => some controller

Limitations.

  • Fiber and custom scopes will not work in browser because browsers doesn't support fibers.
  • Use app.get componentName instead of app.componentName in old browsers not supporting getters and setters syntax. Use set for setting components.

Copyright (c) Alexey Petrushin, http://petrush.in, released under the MIT license.

miconjs's People

Contributors

al6x avatar

Stargazers

 avatar

Watchers

 avatar

miconjs's Issues

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.