-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for "booting" an application from a set of Model / DataSource / app meta-data. #57
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
Conversation
Test PASSed. |
Test PASSed. |
app.model = function (Model, config) { | ||
if(arguments.length === 1) { | ||
assert(typeof Model === 'function', 'app.model(Model) => Model must be a function / constructor'); | ||
this.remotes().exports[Model.pluralModelName] = Model; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert that Model.pluralModelName
is defined?
The new API and design are great, it looks it will be easy to work with it both manually (as a developer/user) and from an IDE/CLI tools. See few comments above, my main concern is about using |
Test PASSed. |
Closing this PR and opening a PR against the named branch that spans multiple repos. |
@ritch I apologize for the lateness of this, I've been excessively bogged down last week. I like it, but have a few comments:
Other than that, looks good. |
You might have to be a bit more specific. If I understand correctly, I agree that having a single file for describing a model is much clearer and more comprehensible than a giagantic JSON file. We have to have JSON that describes the model so that we can generate the LDL / meta data from the editor. I'm not against supporting building
The embedded JS was an interesting idea to allow config to be paramaterized. We are going to solve this with a different approach. Like above, we need to be able to specify settings from the editor or other tools. That is why there is as little config / meta-data in the actual generated code as possible.
Take a look at this PR it has the actual app.js code in it. strongloop/loopback-workspace#14
Can we address this in the workspace PR mentioned above?
Thought we already talked about this at some point. The config needs to be readable and writable. This means JS is not really a realistic option. I won't say anything is impossible, but AST parsing and rebuilding would be incredibly hard compared to |
http://esprima.org/, shouldn't be excessively hard to read/write js, and the inline js is basically writing out own templating engine, which isn't to be taken lightly. Just an idea. I'll comment on the other thread... |
/to @raymondfeng
/cc @bajtos @piscisaureus @sam-github @themitchy @Schoonology
Background
Here is a detailed example application using the new
app.boot()
api. The sample app shows how usingapp.boot()
can simplify our project structure.Current Project Structure
Currently
slc lb
generates a set of modules and an entry file (app.js
).app.js
is a module loader that is baked in as part of the generated code. Itrequire()
s each module in the modules directory and starts the app. Each module is made up of generated code (index.js
) a module description (module.json
) that defines meta-data about the module and one or more config files (config.json
,properties.json
).Issues with the Current Structure
Since each "module" contains an
index.js
file, working on a loopback project usually means having severalindex.js
files open. The example project linked above has clearly named files and directories (eg.models.json
,./models
).The proposed structure wouldn't include any extra generated files. Instead
slc lb
would just update themodels.json
file when scaffolding a model ordatasources.json
when defining a datasource.Propsoed Project Structure
The structure proposed in the example linked above is a bit simpler. There are three config files:
Plus a single entry file:
app.js
is the only file with generated code. It includes the following:When
app.boot()
is called without any arguments, the following is kicked off:datasources.json
in the current directorymodels.json
in the current directory./models
dir are required.New Simpler APIs
This PR also introduces a simpler way of defining and interacting with models:
First you define the data sources your app requires using
app.boot()
.Then you can define a model in a single line:
Furthermore, your models are available from your
app
.Read the updated documentation for more info.