initial commit
This commit is contained in:
20
node_modules/property-accessors/LICENSE.md
generated
vendored
Normal file
20
node_modules/property-accessors/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
Copyright (c) 2013 GitHub Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
80
node_modules/property-accessors/README.md
generated
vendored
Normal file
80
node_modules/property-accessors/README.md
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
# Property Accessors Mixin [](https://travis-ci.org/atom/property-accessors)
|
||||
|
||||
A mixin for defining dynamic properties.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
To define a basic property accessor, use the `accessor` declaration. If you've
|
||||
included the mixin into a class, you define a prototype property by calling
|
||||
`@::accessor` on its prototype.
|
||||
|
||||
```coffee
|
||||
PropertyAccessors = require 'property-accessors'
|
||||
|
||||
class Vehicle
|
||||
PropertyAccessors.includeInto(this)
|
||||
|
||||
@::accessor 'type',
|
||||
get: ->
|
||||
switch @doorCount
|
||||
when 4 then 'sedan' # i know this isn't strictly accurate
|
||||
when 2 then 'coupe'
|
||||
set: (type) ->
|
||||
switch type
|
||||
when 'sedan' then @doorCount = 4
|
||||
when 'coupe' then @doorCount = 2
|
||||
|
||||
car = new Vehicle
|
||||
car.doorCount = 2
|
||||
car.type # => 'coupe'
|
||||
```
|
||||
|
||||
You can define a class-level property by *extending* with the mixin rather than
|
||||
including it (which extends the prototype).
|
||||
|
||||
```coffee
|
||||
class Vehicle
|
||||
PropertyAccessors.extend(this)
|
||||
|
||||
@accessor 'vehicleCount', get: -> @allVehicles.length
|
||||
```
|
||||
|
||||
You can just pass a single function if you only want to define a getter:
|
||||
|
||||
```coffee
|
||||
class Vehicle
|
||||
PropertyAccessors.includeInto(this)
|
||||
|
||||
@::accessor 'type', -> # ...
|
||||
```
|
||||
|
||||
## Fancy Usage
|
||||
|
||||
### Lazy Accessors
|
||||
|
||||
Lazy accessors call a function the first time a property is accessed. You are
|
||||
still free to overwrite this value by assigning the property explicitly.
|
||||
|
||||
```coffee
|
||||
class ScienceLab
|
||||
PropertyAccessors.includeInto(this)
|
||||
|
||||
@::lazyAccessor 'crazyComputation', -> computeCrazyComputation()
|
||||
```
|
||||
|
||||
### Advised Accessors
|
||||
|
||||
Advised accessors allow you to call code before the reading or writing of a
|
||||
property value. If a property is being assigned, your advice function is called
|
||||
with the value being assigned and the old value.
|
||||
|
||||
```coffee
|
||||
class SpyStation
|
||||
@advisedAccessor 'online',
|
||||
get: -> @ensureAllSystemsNominal()
|
||||
set: -> @ensureUserIsSpy()
|
||||
|
||||
station = new SpyStation
|
||||
station.online = true # ensures user is a spy, then assigns true
|
||||
station.online # ensures all systems are nominal, then returns true
|
||||
```
|
||||
74
node_modules/property-accessors/lib/property-accessors.js
generated
vendored
Normal file
74
node_modules/property-accessors/lib/property-accessors.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
(function() {
|
||||
var Mixin, PropertyAccessors, WeakMap, _ref, _ref1,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
Mixin = require('mixto');
|
||||
|
||||
WeakMap = (_ref = global.WeakMap) != null ? _ref : require('es6-weak-map');
|
||||
|
||||
module.exports = PropertyAccessors = (function(_super) {
|
||||
__extends(PropertyAccessors, _super);
|
||||
|
||||
function PropertyAccessors() {
|
||||
_ref1 = PropertyAccessors.__super__.constructor.apply(this, arguments);
|
||||
return _ref1;
|
||||
}
|
||||
|
||||
PropertyAccessors.prototype.accessor = function(name, definition) {
|
||||
if (typeof definition === 'function') {
|
||||
definition = {
|
||||
get: definition
|
||||
};
|
||||
}
|
||||
return Object.defineProperty(this, name, definition);
|
||||
};
|
||||
|
||||
PropertyAccessors.prototype.advisedAccessor = function(name, definition) {
|
||||
var getAdvice, setAdvice, values;
|
||||
if (typeof definition === 'function') {
|
||||
getAdvice = definition;
|
||||
} else {
|
||||
getAdvice = definition.get;
|
||||
setAdvice = definition.set;
|
||||
}
|
||||
values = new WeakMap;
|
||||
return this.accessor(name, {
|
||||
get: function() {
|
||||
if (getAdvice != null) {
|
||||
getAdvice.call(this);
|
||||
}
|
||||
return values.get(this);
|
||||
},
|
||||
set: function(newValue) {
|
||||
if (setAdvice != null) {
|
||||
setAdvice.call(this, newValue, values.get(this));
|
||||
}
|
||||
return values.set(this, newValue);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
PropertyAccessors.prototype.lazyAccessor = function(name, definition) {
|
||||
var values;
|
||||
values = new WeakMap;
|
||||
return this.accessor(name, {
|
||||
get: function() {
|
||||
if (values.has(this)) {
|
||||
return values.get(this);
|
||||
} else {
|
||||
values.set(this, definition.call(this));
|
||||
return values.get(this);
|
||||
}
|
||||
},
|
||||
set: function(value) {
|
||||
return values.set(this, value);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return PropertyAccessors;
|
||||
|
||||
})(Mixin);
|
||||
|
||||
}).call(this);
|
||||
43
node_modules/property-accessors/package.json
generated
vendored
Normal file
43
node_modules/property-accessors/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "property-accessors",
|
||||
"version": "1.1.3",
|
||||
"description": "A mixin for declaring property accessors",
|
||||
"main": "lib/property-accessors",
|
||||
"scripts": {
|
||||
"test": "grunt test",
|
||||
"publish": "grunt"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/atom/property-accessors"
|
||||
},
|
||||
"keywords": [
|
||||
"property",
|
||||
"accessors",
|
||||
"metaprogramming"
|
||||
],
|
||||
"author": "Nathan Sobo",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://github.com/atom/telepath/raw/master/LICENSE.md"
|
||||
}
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/atom/property-accessors/issues"
|
||||
},
|
||||
"homepage": "http://atom.github.io/property-accessors/",
|
||||
"dependencies": {
|
||||
"mixto": "1.x",
|
||||
"es6-weak-map": "^0.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jasmine-focused": "1.x",
|
||||
"grunt-contrib-coffee": "~0.7.0",
|
||||
"grunt-cli": "~0.1.8",
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-shell": "~0.2.2",
|
||||
"grunt-coffeelint": "0.0.6",
|
||||
"rimraf": "~2.2.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user