property-accessors

WebJar for property-accessors

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

property-accessors
Last Version

Last Version

1.1.3
Release Date

Release Date

Type

Type

jar
Description

Description

property-accessors
WebJar for property-accessors
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/atom/property-accessors

Download property-accessors

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/property-accessors/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>property-accessors</artifactId>
    <version>1.1.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/property-accessors/
implementation 'org.webjars.npm:property-accessors:1.1.3'
// https://jarcasting.com/artifacts/org.webjars.npm/property-accessors/
implementation ("org.webjars.npm:property-accessors:1.1.3")
'org.webjars.npm:property-accessors:jar:1.1.3'
<dependency org="org.webjars.npm" name="property-accessors" rev="1.1.3">
  <artifact name="property-accessors" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='property-accessors', version='1.1.3')
)
libraryDependencies += "org.webjars.npm" % "property-accessors" % "1.1.3"
[org.webjars.npm/property-accessors "1.1.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : mixto jar [1,2)
org.webjars.npm : es6-weak-map jar [0.1.2,0.2)

Project Modules

There are no modules declared in this project.

Property Accessors Mixin

OS X Build Status Windows Build Status Dependency Status

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.

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).

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:

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.

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.

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
org.webjars.npm

Atom

Free and open source text editor, brought to you by GitHub

Versions

Version
1.1.3