Comments (4)
Related #28
from resource.
There are a few competing factors here in the API
- 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 theconnect
dep is installed.http.start
will defer until the asynchronous installation ofconnect
completes.http.start
is available now because ofrequire("resources")
, which we shouldn't be doing. - 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. - For
require("resource-http")
to work,resource-http
will need to already be installed in the application. - Without
resource.use
, we lose ability to dynamically add new functionality to an already running app.
from resource.
There are a few possible solutions.
- Implement a sync npm installer / script load.
- Requires c addon.
- Won't work in browser.
- 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
- 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.
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)
- JSHINT codebase
- support for nested resources HOT 5
- Migrate all non-core resource code into new resources: [logger], [schema], [persistence] HOT 4
- schema for return values of resource method HOT 2
- Setup TravisCI for resource tests HOT 1
- Better UX for displaying installation of missing deps and resource copying
- Make `resource.use` and `resource.load` resource methods HOT 1
- Add `Resource.init` method detection
- resource.use('') fails HOT 4
- change .get and .destroy to take (options, callback) like everything else HOT 1
- make resource into a resource HOT 1
- Chaining .use resources HOT 6
- resource.resources should be object containing subresources of resource
- [refactor] `resource.use` to use package.json HOT 1
- Creating new resources changes the schema on the resource HOT 1
- Remove JugglingDB / Simplify Persistence Layer HOT 4
- auto-create database for couchdb if database is missing
- Should not found be an error? HOT 1
- Issue with Resource.all missing options
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resource.