Skip to content

Instantly share code, notes, and snippets.


Ritchie Martori ritch

  • Fremont, California
View GitHub Profile
View sequence.example.ts
interface Envelope {
class File extends Envelope {
writeToResponse(res) {
res.setHeader('content-type', this.getContentType())
ritch /
Last active Aug 29, 2015
LoopBack 3 with Mixins as First Class Citizens

LoopBack 3

Core + Boot + Connector refactor

0. setup

  • all components loaded into registry
  • all mixins loaded into registry
  • registry mixins applied
  • create models, apply model configs, etc
  • create data sources
ritch /
Created Jul 30, 2015
Next Generation of Model and Boot Scripts

Model and Boot Scripts

Currently, model scripts and the way they are loaded are a bit naive.

Take a look at this example:

// models/my-model.js
module.exports = function(MyModel) {
  MyModel.findFooBars = function(filter, cb) {
ritch / controller.js
Last active Aug 29, 2015
Idea to simplify the definition of angular modules
View controller.js
* @module myServiceModule
* @controller MyController
* @inject $scope notify
$scope.callNotify = function(msg) {
ritch / preferences.js
Last active Feb 2, 2017
Input files for the Express.js scaffolding tool
View preferences.js
var $ = exports
ritch / comparison.js
Last active Aug 29, 2015
Vanilla Express / Express + co comparison
View comparison.js
// my existing express app
function myMiddleware(req, res, next) {
doSomething(next); // does something async + takes a callback
app.get('/', function(req, res, next) {
getHomePageData(function(err, data) {

Lessons Learned from Stateful Modules


We forked the jugglingdb module to create loopback's orm. Jugglingdb allows you to define models and the relations between them. One of the fundemental mechanisms that it uses to do this is the type registry.

You can see this implemented in the original jugglingdb project

exports.Schema = Schema;
ritch /
Created May 12, 2014
How might we zonify loopback?

Here is a basic (truncated) callstack for a REST request to loopback.

  • GET /users
    • loopback.token()
    • Model.checkAccess()
    • sharedMethod.invoke(argsFromHttpCtx)
      • User.find()
        • connector.find()
          • driver.find()
ritch /
Last active Aug 29, 2015
FAQ for LoopBack replication

Will it be possible to use continuous replication, so the client immediately triggers a replication when local data changes. And the server uses a push mechanism?

Yes... here is a basic example that relies on a style EventEmitter.

// psuedo-server.js
MyModel.on('changed', function(obj) {
ritch /
Last active Aug 29, 2015
From 0 to MongoDB in 30 seconds...
# Run the following steps in your terminal...
# make sure you have node and mongo installed
npm install strong-cli
# create a loopback project
slc lb project mongo-example
cd mongo-example
# create a loopback model
You can’t perform that action at this time.