Skip to content

Commit

Permalink
Merge pull request #2 from hightail/updates/version-4
Browse files Browse the repository at this point in the history
Updates/version 4
  • Loading branch information
hunternovak authored Aug 30, 2017
2 parents 2686eed + 725e4a1 commit a3860d9
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 321 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Idea project file
*.iml

## Directory-based project format:
.idea/

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties


6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wilson - v3.1.0
# Wilson - v4.1.2

Wilson is framework that adds a distinct component abstraction to Angularjs web applications. These components
can be lazily-loaded at route-time automatically based on dependencies (this works in conjunction with the Wilson
Expand Down Expand Up @@ -27,6 +27,8 @@ wilson.utility('MyUtility', [..., function(...) { }]);
wilson.class('MyClass', [..., function(...) { }]);
wilson.filter('MyFilter', [..., function(...) { }]);
wilson.router([..., function(...) { }]);
```

Although this initial declaration is not specifically on the 'angular' global instance, under-the-hood, wilson
Expand All @@ -47,6 +49,8 @@ wilson.class() ---> angular.factory()
wilson.utility() ---> angular.factory()
wilson.filter() ---> angular.filter()
wilson.router() ---> angular.factory()
```

Wilson ensures that some base options provided to angular so that these constructs are represented appropriately, but as
Expand Down
34 changes: 24 additions & 10 deletions best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ This is the recommended pattern:

```js
wilson.component('my-component', {
transclude: true, // Optional
scriptDependencies: [], // Optional
scope: {}, // Optional
exports: {}, // Optional
inherit: {}, // Optional
require: [], // Optional
controller: [function() {}], // Required
link: function($scope, $element, $attrs, controller) {} // Optional
Expand All @@ -24,22 +27,34 @@ wilson.component('my-component', {
___

**2 *Avoid using "this" to reference a controller instance. Store a local "controller" reference.***
**2 *Avoid using "this" in a component controller. Use private functions or declare them on the $scope so that they can be used in from the view.***

Wilson components treat $scope as the effective controller. All controller functions should be declared privately or
publicly (on the $scope instance). This keeps consistency in the pattern that $scope represents a component instance.

This makes access to the controller instance very explicit. It also keeps consistency with the
"controller" parameter in the **link** method. This "controller" reference should be declared as the
first line of each component controller.

```js
wilson.component('my-component', {
controller: ['$scope', function($scope) {
var controller = this; // This is recommended in every controller

function foo(msg) { // GOOD - Explicit private function only available inside this controller
alert(msg);
};

$scope.bar = function bar(msg) { // GOOD - Explicit $scope function available in the controller and view
alert(msg);
};

this.foobar = function foobar(msg) { // BAD - "this" is on the controller which is not used
alert(msg);
};

}]
});
```
___

**3 *Declare explicit function names for all $scope and controller functions***
**3 *Declare explicit function names for all $scope functions***

This makes debugging much easier for the developer. If an error prints to the console, the
stack trace will have a function name to point out where the problem occurred. Without it the
Expand All @@ -48,15 +63,14 @@ console will print "Anonymous Function" which is ambiguous and does not help wit
```js
wilson.component('my-component', {
controller: ['$scope', function($scope) {
var controller = this;


$scope.message = '';

$scope.updateMessage = function updateMessage(message) { // GOOD - Function name matches the property name
$scope.message = message;
};

controller.clearMessage = function() { $scope.message = ''; }; // BAD - Function has no name
$scope.clearMessage = function() { $scope.message = ''; }; // BAD - Function has no name
}]
});
```
Expand Down Expand Up @@ -101,7 +115,7 @@ wilson.service('MyService', ['$rootScope', function($rootScope) {

service.doSomethingElse = function doSomethingElse() {};

service.doALlTheThings = function doAllTheThings() {};
service.doAllTheThings = function doAllTheThings() {};

return service;
}]);
Expand Down
Loading

0 comments on commit a3860d9

Please sign in to comment.