Skip to main content
Commonmark migration
Source Link

##Enumerated Constants, or enums, in Soapi.js

Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text

Next: Studio JavaScript Intellisense and Code Completion Support

##Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text

Next: Studio JavaScript Intellisense and Code Completion Support

Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text

Next: Studio JavaScript Intellisense and Code Completion Support

broken image fixed (click 'rendered output' to see the difference; images retrieved via Wayback Machine); for more info, see https://gist.github.com/Glorfindel83/9d954d34385d2ac2597bbe864466259f
Source Link

##Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text http://soapi.info/images/soapi.js.enums1.pngalt text

Next: Studio JavaScript Intellisense and Code Completion Support

##Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text http://soapi.info/images/soapi.js.enums1.png

Next: Studio JavaScript Intellisense and Code Completion Support

##Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text

Next: Studio JavaScript Intellisense and Code Completion Support

replaced http://stackapps.com/ with https://stackapps.com/
Source Link

##Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text http://soapi.info/images/soapi.js.enums1.png

Next: Studio JavaScript Intellisense and Code Completion SupportStudio JavaScript Intellisense and Code Completion Support

##Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text http://soapi.info/images/soapi.js.enums1.png

Next: Studio JavaScript Intellisense and Code Completion Support

##Enumerated Constants, or enums, in Soapi.js

The advantages of using enums include the elimination of magic strings scattered about your codebase and the ability to update all references to an enum value in one location.

Typically, in a statically typed language, enums are readonly or immutable values. While this concept is alien to the dynamically typed JavaScript language the benefits of enums are not mitigated. You simply need to treat them as immutable and not assign values to them.

Soapi.js defines 'enums' for all of the 'choice' parameters and return types in the API. Using enums may seem like more work in that they are more verbose than using string constant but in reality they make your code more robust and much easier to read and maintain.

For example:

var $sd = Soapi.Domain;

// as a parameter

route.Sort = $sd.UserSort.reputation;


// identifying values in return types

switch(user.user_type){
   case $sd.UserType.anonymous:
      // do something 
      break;
   case $sd.UserType.unregistered:
      // do something 
      break;
   case $sd.UserType.registered:
      // do something 
      break;
   case $sd.UserType.moderator:
      // do something 
      break;
}

Enums used in parameters

SortOrder

  • desc
  • asc

PostSort

  • activity
  • views
  • creation
  • votes

CommentSort

  • creation
  • votes

QuestionSort

  • activity
  • votes
  • creation
  • featured
  • hot
  • week
  • month

TagSort

  • popular
  • activity
  • name

UserSort

  • reputation
  • creation
  • name

FavoritesSort

  • activity
  • views
  • creation
  • added
  • votes

Enums used in return types

SiteState

  • normal
  • closed_beta
  • open_beta
  • linked_meta

UserType

  • anonymous
  • unregistered
  • registered
  • moderator

PostType

  • question
  • answer

PostTimelineType

  • question
  • answer
  • comment
  • revision
  • votes
  • state
  • accepted
  • unaccepted

RevisionType

  • single_user
  • vote_based

UserTimelineType

  • comment
  • askoranswered
  • badge
  • revision
  • accepted

Users of Visual Studio will get extra benefit from the use of the defined enum types as they have the luxury of intellisense code completion, which will be covered in detail in the Intellisense Support post.

alt text http://soapi.info/images/soapi.js.enums1.png

Next: Studio JavaScript Intellisense and Code Completion Support

added 134 characters in body
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
deleted 978 characters in body; added 5 characters in body
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
added 410 characters in body; added 4 characters in body
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60
Loading