Giter VIP home page Giter VIP logo

Comments (6)

tardyp avatar tardyp commented on July 17, 2024

Hi,

Guanlecoja is a build system designed for AngularJS. AngularJs does provide component reusability through services (and other components). You should create an angular service (optionally via ng-classify) in any file, and use it via dependency injection anywhere.

Problem with defining classes by yourself is that you would have to worry about parsing order of files. Your classes need to be defined before the classes that are using them. Angularjs takes care of all of the via dependency injection.

from guanlecoja.

uglycoyote avatar uglycoyote commented on July 17, 2024

Sounds good, I'll make the shared code code a service then! Thanks!

from guanlecoja.

uglycoyote avatar uglycoyote commented on July 17, 2024

After exploring this route, refactoring common code into a service seems like it would not always be the appropriate way to solve the problem, since Services appear to impose some additional constraints that may be undesired.

  1. Services are singletons. (according to https://docs.angularjs.org/guide/services). You may not want your refactored class to be a singleton, you may want to create multiple instances of it, e.g. so that they can hold different state or so you can pass in different configuration options to each instance of the refactored class.
  2. Converting code into a service seems to change the lifespan of that object. E.g., if I have a class that used to be instantiated when the controller is created and I turn that class into a service, then it exists before the Controller and is reused if other controllers are created (e.g. you leave the page and come back again)

My conclusion is that while factoring common code into a Service may be the right way to go sometimes, it is not always the correct decision. So I would like to reopen my question about whether guanlecoja provides some means where you can import a class defined in file A into a class defined in file B?

from guanlecoja.

tardyp avatar tardyp commented on July 17, 2024

I think you will need to use the factory design pattern in that case.

class Tool
     method1: => return 'foo'

class UtilFactory extends Service
      newTool: -> return new Tool()

then in your other components:

myController = (UtilFactoryService) ->  # angularjs injected function
     tool = UtilFactoryService.newTool()

Again, this is more an angularjs problem than a guanlecoja issue, you should look there on StackOverflow

from guanlecoja.

uglycoyote avatar uglycoyote commented on July 17, 2024

My question is really a question about bundling, not about Angular, unless Angular is what's actually doing the bundling, but as far as I can tell it is not. Is Angular what's actually producing the scripts.js in the guanlecoja build system? As far as I can tell from my internet research, bundling is not a problem that Angular tries to solve, instead people tack on additional systems (e.g. webpack, browserify, perhaps gulp) to do the bundling.

What is doing the bundling in guanlecoja?

from guanlecoja.

tardyp avatar tardyp commented on July 17, 2024

guanlecoja uses gulp-concat for bundling. That is the very simplest bundler that exists.
guanlecoja only manage order of the bower dependencies, which is the order that is declared in config.coffee.

For the order of the app's files, there is no particular order defined.

Angular does not manage bundling, but it manage dependencies, via dependency injection. So if an app is pure angularjs, there is no need for complex bundling system, you just need to load all the JS, and angular bootstrap system will work.

You can see this article for a longer comparaison of bundler, and how angularjs solve the dependency ordering problem
https://medium.com/@jdxcode/best-practices-for-building-angular-js-apps-266c1a4a6917

from guanlecoja.

Related Issues (1)

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.