Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how and where to look for resources #27

Closed
ahdinosaur opened this issue Jul 15, 2013 · 4 comments
Closed

how and where to look for resources #27

ahdinosaur opened this issue Jul 15, 2013 · 4 comments
Labels

Comments

@ahdinosaur
Copy link

this is something that needs to be finalized, implemented, and tested, so here's what i am thinking so far.

install (async):

  • if in appDir + '/resources'/, npm install to appDir + '/node_modules/'
  • if not in appDir + '/node_modules/', npm install resource package from npm registry
  • install any dependencies that are not already installed to appDir + '/node_modules/' + resource.path

use (async):

  • install and load

load (sync):

  • require resource from appDir + '/node_modules/'
@Marak
Copy link
Member

Marak commented Jul 19, 2013

Related #28

@Marak
Copy link
Member

Marak commented Jul 20, 2013

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.

@Marak
Copy link
Member

Marak commented Jul 21, 2013

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.

@Marak
Copy link
Member

Marak commented Dec 20, 2013

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.

@Marak Marak closed this as completed Dec 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants