From a8808d0635c854739fca38cfad605e294bdf8363 Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Sat, 21 Mar 2015 18:08:55 +0100 Subject: [PATCH 1/4] make components written in LiveScript work - typeof null === 'object', so check for null - put LiveScript detection into its own function --- lib/components.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/components.js b/lib/components.js index ce27131f3..a982a6bf0 100644 --- a/lib/components.js +++ b/lib/components.js @@ -161,11 +161,13 @@ SingletonComponentFactory.prototype.init = function(context) { SingletonComponentFactory.prototype.create = function() {}; App.prototype.component = function(viewName, constructor) { - if (typeof viewName === 'function') { + if (viewName && (typeof viewName === 'function' || typeof viewName === 'object')) { constructor = viewName; viewName = null; } + constructor = extractLiveScriptConstructor(constructor); + // Inherit from Component extendComponent(constructor); @@ -197,6 +199,18 @@ App.prototype.component = function(viewName, constructor) { return this; }; + +function extractLiveScriptConstructor(constructor) { + if (typeof constructor === 'object') { + var keys = Object.keys(constructor); + if (keys.length == 1) { + return constructor[keys[0]]; + } + } + return constructor; +} + + function extendComponent(constructor) { // Don't do anything if the constructor already extends Component if (constructor.prototype instanceof Component) return; From 65e6abe129b77fd02febd6e050905ebc1147c0bb Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Thu, 12 Mar 2015 00:04:22 +0100 Subject: [PATCH 2/4] allow components to have a separate style file specify the style file with component.prototype.style --- lib/components.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/components.js b/lib/components.js index ce27131f3..65230d082 100644 --- a/lib/components.js +++ b/lib/components.js @@ -185,6 +185,11 @@ App.prototype.component = function(viewName, constructor) { } } + if (constructor.prototype.style) { + var styleFilename = constructor.prototype.style; + this.loadStyles(styleFilename); + } + // Associate the appropriate view with the component type var view = this.views.find(viewName); if (!view) { From c01b85b87e5a017d4f20467aa800eb0f7c68d92d Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Mon, 14 Dec 2015 00:50:45 -0800 Subject: [PATCH 3/4] allow to use subcomponents usage: MyComponent.prototype.name = 'maincomponent' MyComponent.prototype.components = [require('subcomponent')] result: maincomponent maincomponent:subcomponent --- lib/components.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/components.js b/lib/components.js index ce27131f3..67107152c 100644 --- a/lib/components.js +++ b/lib/components.js @@ -160,7 +160,7 @@ SingletonComponentFactory.prototype.init = function(context) { // Don't call the create method for singleton components SingletonComponentFactory.prototype.create = function() {}; -App.prototype.component = function(viewName, constructor) { +App.prototype.component = function(viewName, constructor, ns) { if (typeof viewName === 'function') { constructor = viewName; viewName = null; @@ -169,15 +169,23 @@ App.prototype.component = function(viewName, constructor) { // Inherit from Component extendComponent(constructor); + // Set namespace to the component if it's passed along + if (ns) + constructor.prototype.ns = ns; + // Load template view from filename if (constructor.prototype.view) { var viewFilename = constructor.prototype.view; viewName = constructor.prototype.name || path.basename(viewFilename, '.html'); + if (ns) + viewName = ns + ':' + viewName; this.loadViews(viewFilename, viewName); } else if (!viewName) { if (constructor.prototype.name) { viewName = constructor.prototype.name; + if (ns) + viewName = ns + ':' + viewName; var view = this.views.register(viewName); view.template = templates.emptyTemplate; } else { @@ -185,6 +193,13 @@ App.prototype.component = function(viewName, constructor) { } } + // Load sub components + var subComponents = constructor.prototype.components; + if (subComponents) { + for (var i = 0, len = subComponents.length; i < len; i++) { + this.component(null, subComponents[i], viewName); + } + } // Associate the appropriate view with the component type var view = this.views.find(viewName); if (!view) { From 04e0324fc838a7bb44414436fcccfcc321f18293 Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Mon, 14 Dec 2015 01:10:49 -0800 Subject: [PATCH 4/4] update README and dependencies --- README.md | 7 +++++++ package.json | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6b2cf3d57..abd14cab7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ [![browser support](https://ci.testling.com/derbyjs/derby.png)](https://ci.testling.com/derbyjs/derby) [![build status](https://api.travis-ci.org/derbyjs/derby.png)](http://travis-ci.org/derbyjs/derby) +# Changes in this fork + +- support for local component styles +- support for subcomponents +- support for components written in LiveScript + + # Derby The Derby MVC framework makes it easy to write realtime, collaborative applications that run in both Node.js and browsers. diff --git a/package.json b/package.json index 45bf4f349..faaa38c30 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,10 @@ }, "dependencies": { "chokidar": "^1.2.0", - "derby-parsing": "^0.4.1", - "derby-templates": "^0.3.3", + "derby-parsing": "michael-brade/derby-parsing", + "derby-templates": "michael-brade/derby-templates", "html-util": "^0.2.1", - "racer": "^0.7.0", + "racer": "michael-brade/racer", "resolve": "^1.1.6", "through": "^2.3.4", "tracks": "^0.5.0"