UNPKG

4.03 kBMarkdownView Raw
1# Roadmap
2
3In this document you will find a proposed list of features that will be released during the Lux `1.0` lifecycle.
4
5
6## Router Namespaces
7
8Similar to [Rails](http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing), Lux should provide a simple API for defining a router namespace. There are a number of common use cases for router namespaces that make this feature a must. API versioning and a simple way to define "Admin Only" are two good examples.
9
10#### API
11
12##### Routes
13
14Defining router namespaces will be done in the `routes.js` file where you currently define your applications resources and routes.
15
16Similar to the `resource` and `route` arguments, the `namespace` argument will also be a function.
17
18```javascript
19// ./app/routes.js
20export default function routes() {
21 this.resource('posts');
22
23 this.namespace('admin', function admin(route, resource) {
24 this.resource('posts');
25 });
26}
27```
28
29There will also be the ability to pass an options hash as the second argument to the `namespace` function with properties such as `mount` in case the name of a declared namespace is different from the intended mount point.
30
31```javascript
32// ./app/routes.js
33export default function routes() {
34 this.namespace('legacy', {
35 mount: 'v1'
36 }, function legacy() {
37 this.resource('posts');
38 });
39
40 this.namespace('current', {
41 mount: 'v2'
42 }, function current() {
43 this.resource('posts');
44 });
45}
46```
47
48##### Controllers
49
50When you declare a namespace, Lux will expect that namespace to have it's own directory and `ApplicationController` in the `./controllers` directory.
51
52```
53controllers
54├── admin
55│   ├── application.js
56│   └── posts.js
57├── application.js
58└── posts.js
59```
60
61This is the difference between a namespace and nested route. Namespaces have an `ApplicationController` unique to the namespace. This allows for middleware to be declared at the namespace level.
62
63```javascript
64// ./app/controllers/application.js
65class ApplicationController extends Controller {
66 beforeAction = [
67 async function authorizeUser(req, res) {
68 // Ensure a user is logged in.
69 }
70 ];
71}
72
73// ./app/controllers/admin/application.js
74class AdminController extends Controller {
75 beforeAction = [
76 async function authorizeAdmin(req, res) {
77 // Ensure an admin is logged in.
78 }
79 ];
80}
81```
82
83##### Nesting
84
85Namespaces nesting will be supported without a limit to the level of nesting. Even though middleware appears to be a nested tree structure during the declaration, Lux will flatten and cache these functions as a one dimensional array upon the application's boot sequence.
86
87Here is the middleware that would be executed when a user visits `/posts`
88
89```javascript
90[
91 authorizeUser,
92 PostsController.index
93]
94```
95
96Here is the middleware that would be executed when a user visits `/admin/posts`
97
98```javascript
99[
100 authorizeUser,
101 authorizeAdmin,
102 AdminPostsController.index
103]
104```
105
106[\* Middleware flattening already is implemented in the current release of Lux.](https://github.com/postlight/lux/blob/master/src/packages/route/utils/create-action.js#L31)
107
108
109## Polymorphic Relationships (#75)
110
111#### API
112
113Declaring a polymorphic relationship on a model should be as simple as a boolean flag.
114
115```javascript
116class Comment extends Model {
117 static hasOne = {
118 commentable: {
119 polymorphic: true
120 }
121 }
122}
123
124class Post extends Model {
125 static hasMany = {
126 comments: {
127 model: 'comment',
128 inverse: 'commentable'
129 }
130 }
131}
132```
133
134The example above would create the columns `commentable_id` and `commentable_type` on the `comments` table.
135
136
137--
138
139
140## In Progress
141
142Below is a list of features that will likely be a part of the `1.0` release but their API is still in very early stages.
143
144* WebSockets
145 * Controller API
146 * Model Hook API
147
148* Application Testing
149 * Test Generators
150 * Debugging Tools
151 * ~~Generated SQL Logging ([#48](https://github.com/postlight/lux/issues/48))~~
152 * Implemented in #65