Giter VIP home page Giter VIP logo

Comments (4)

Marak avatar Marak commented on June 24, 2024

Related #28

from resource.

Marak avatar Marak commented on June 24, 2024

There are a few competing factors here in the API

  1. Resource method deferment requires that the resource schema is already loaded in memory. This is best illustrated by trying to call something like http.start before the connect dep is installed. http.start will defer until the asynchronous installation of connect completes. http.start is available now because of require("resources"), which we shouldn't be doing.
  2. It's not reasonable to expect users to require the resources package for every app they build. resources has lazy npm deps for it's individual resources, but the code size will just keep getting larger as more resources are added.
  3. For require("resource-http") to work, resource-http will need to already be installed in the application.
  4. Without resource.use, we lose ability to dynamically add new functionality to an already running app.

from resource.

Marak avatar Marak commented on June 24, 2024

There are a few possible solutions.

  1. Implement a sync npm installer / script load.
    • Requires c addon.
    • Won't work in browser.
  2. Require that all resources are explicitly defined before the application is started
    • Makes interacting with a running application difficult
    • Will require static code analysis to help users
  3. Implement a ready event for resources. No resource methods can be called before this event is fired.
    • Will break previous API slightly ( but not much )
    • Will work in browser
    • Can piggy-back off existing init event and call it a day

3 seems to be the best choice.

All resources will be npm packages. resource.use will be small wrapper for require. resource packages are always installed into the current application. deps for those resources are always stored in their own individual node_modules/ folder inside each resource.

The code would look something like:

#!/usr/bin/env node

var resource = require('resource');

var admin = resource.use('admin');

resource.use('account', { datasource: "fs"});
resource.use('creature', { datasource: "fs"});

admin.on('init', function() {
  admin.start(function (err, server) {
    var address = server.address();
    resource.logger.info('admin server started on http://' + address.address + ":" + address.port + "/admin")
    resource.logger.help('username and password are admin');
  });
});

There could also be an aggregate resource.init event which fires after all resource.use from the first event loop tick have completed.

This same approach should work well in the browser as well. The core problem that needs to get solved is the fact we are doing remote dependency installation at run-time. This operation is inherently an asynchronous event, and without a reliable __noSuchMethod__ there isn't good way to deal with it.

from resource.

Marak avatar Marak commented on June 24, 2024

This is solved in version 5.

I've opted out of async loading of resource dependencies and ready states. The easiest way in development is to use option 2, require that all resources are explicitly defined before application start.

resource.use no longer loads new resources. All resources must now be required before application start. This makes for a simpler application development environment.

from resource.

Related Issues (20)

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.