JQUERY $(element, plainObject)

I ran across this article and a set of interesting jquery syntax:  $(‘<li>’, { text: formatItem(item) }).appendTo($(‘#products’));

So after stumping a few folks and searching the jquery documentation I figured out what exactly it is doing mostly.

This explains the syntax:  http://api.jquery.com/jquery/#jQuery-html-attributes

This explains why its flexibility can lead to unintended consequences…

While the second argument is convenient, its flexibility can lead to unintended consequences (e.g. $( “<input>”, {size: “4”} ) calling the .size() method instead of setting the size attribute).

So why not just use attr() to add the attribute text?

http://api.jquery.com/attr/#attr-attributeName

 

 

$(document).ready(function () {
// Send an AJAX request
$.getJSON(uri)
.done(function (data) {
// On success, ‘data’ contains a list of products.
$.each(data, function (key, item) {
// Add a list item for the product.
$(‘<li>’, { text: formatItem(item) }).appendTo($(‘#products’));
});
});
});

function formatItem(item) {
return item.Name + ‘: $’ + item.Price;
}

 

I promise, just wait will ya while I do…

A traditional synchronous callback structure versus asynchronous promise equivalent

synchronous

try {
  var value = myFunction();
  console.log(value);
} catch(err) {
  console.log(err);
}

asynchronous

myFunction().then(function(value) {
  console.log(value);
}).catch(function(err) {
  console.log(err);
});

 

In the sync example you would have to wait until myfunction completed before any more code could be executed.  I am sure you have seen sites where the browser UI seems locked up or non-responsive… this kind of code can be the culprit.

The second example returns a promise for the value, then the rest of the code can carry on.  Like rendering a GRID that will hold the data the promise is fetching…  etc…

 

 

 

WEB API 2

In the past you had to configure http responses like this:

 throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));

or

 return new HttpResponseMessage(HttpStatusCode.OK);

 

Now you can do the following:

 public IHttpActionResult GetProduct(int id)
 {
 var product = products.FirstOrDefault((p) => p.Id == id);
 if (product == null)
 {
 return NotFound();
 }
 return Ok(product);
 }

Here are a few articles about it and a working example download

Download will work in VS 2015 or 2017 – just make sure you unlock after unzipping and use package manager to restore packages in vs.

ApiController helper methods like OK)_, NotFound() and more…

Name Description
System_CAPS_protmethod BadRequest()

Creates a BadRequestResult.

System_CAPS_protmethod BadRequest(ModelStateDictionary)

Creates an InvalidModelStateResult with the specified model state.

System_CAPS_protmethod BadRequest(String)

Creates an T:System.Web.Http.Results.ErrorMessageResult (400 Bad Request) with the specified error message.

System_CAPS_protmethod Conflict()

Creates a ConflictResult (409 Conflict).

System_CAPS_protmethod Content<T>(HttpStatusCode, T)

Creates a <see cref=”T:System.Web.Http.NegotiatedContentResult`1″ /> with the specified values.

System_CAPS_protmethod Content<T>(HttpStatusCode, T, MediaTypeFormatter)

Creates a <see cref=”T:System.Web.Http.FormattedContentResult`1″ /> with the specified values.

System_CAPS_protmethod Content<T>(HttpStatusCode, T, MediaTypeFormatter, MediaTypeHeaderValue)

Creates a <see cref=”T:System.Web.Http.FormattedContentResult`1″ /> with the specified values.

System_CAPS_protmethod Content<T>(HttpStatusCode, T, MediaTypeFormatter, String)

Creates a <see cref=”T:System.Web.Http.FormattedContentResult`1″ /> with the specified values.

System_CAPS_protmethod Created<T>(String, T)

Creates a CreatedNegotiatedContentResult<T> (201 Created) with the specified values.

System_CAPS_protmethod Created<T>(Uri, T)

Creates a CreatedNegotiatedContentResult<T> (201 Created) with the specified values.

System_CAPS_protmethod CreatedAtRoute<T>(String, IDictionary<String, Object>, T)

Creates a CreatedAtRouteNegotiatedContentResult<T> (201 Created) with the specified values.

System_CAPS_protmethod CreatedAtRoute<T>(String, Object, T)

Creates a CreatedAtRouteNegotiatedContentResult<T> (201 Created) with the specified values.

System_CAPS_pubmethod Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

System_CAPS_protmethod Dispose(Boolean)

Releases the unmanaged resources that are used by the object and, optionally, releases the managed resources.

System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_pubmethod ExecuteAsync(HttpControllerContext, CancellationToken)

Executes asynchronously a single HTTP operation.

System_CAPS_protmethod Finalize()

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_protmethod Initialize(HttpControllerContext)

Initializes the ApiController instance with the specified controllerContext.

System_CAPS_protmethod InternalServerError()

Creates an InternalServerErrorResult (500 Internal Server Error).

System_CAPS_protmethod InternalServerError(Exception)

Creates an ExceptionResult (500 Internal Server Error) with the specified exception.

System_CAPS_protmethod Json<T>(T)

Creates a JsonResult<T> (200 OK) with the specified value.

System_CAPS_protmethod Json<T>(T, JsonSerializerSettings)

Creates a JsonResult<T> (200 OK) with the specified values.

System_CAPS_protmethod Json<T>(T, JsonSerializerSettings, Encoding)

Creates a JsonResult<T> (200 OK) with the specified values.

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_protmethod NotFound()

Creates a NotFoundResult.

System_CAPS_protmethod Ok()

Creates an OkResult (200 OK).

System_CAPS_protmethod Ok<T>(T)

Creates an OkNegotiatedContentResult<T> with the specified values.

System_CAPS_protmethod Redirect(String)

Creates a redirect result (302 Found) with the specified value.

System_CAPS_protmethod Redirect(Uri)

Creates a redirect result (302 Found) with the specified value.

System_CAPS_protmethod RedirectToRoute(String, IDictionary<String, Object>)

Creates a redirect to route result (302 Found) with the specified values.

System_CAPS_protmethod RedirectToRoute(String, Object)

Creates a redirect to route result (302 Found) with the specified values.

System_CAPS_protmethod ResponseMessage(HttpResponseMessage)

Creates a ResponseMessageResult with the specified response.

System_CAPS_protmethod StatusCode(HttpStatusCode)

Creates a T:System.Web.Http.StatusCodeResult with the specified status code.

System_CAPS_pubmethod ToString()

(Inherited from Object.)

System_CAPS_protmethod Unauthorized(AuthenticationHeaderValue[])

Creates an UnauthorizedResult (401 Unauthorized) with the specified values.

System_CAPS_protmethod Unauthorized(IEnumerable<AuthenticationHeaderValue>)

Creates an UnauthorizedResult (401 Unauthorized) with the specified values.

System_CAPS_pubmethod Validate<TEntity>(TEntity)

Validates the given entity and adds the validation errors to the model state under the empty prefix, if any.

System_CAPS_pubmethod Validate<TEntity>(TEntity, String)

Validates the given entity and adds the validation errors to the model state, if any.

Repost: Dependency Injection in ASP.NET Core

By Steve Smith and Scott Addie

ASP.NET Core is designed from the ground up to support and leverage dependency injection. ASP.NET Core applications can leverage built-in framework services by having them injected into methods in the Startup class, and application services can be configured for injection as well. The default services container provided by ASP.NET Core provides a minimal feature set and is not intended to replace other containers.2

View or download sample code (how to download)

…  Click to route to orignal article

REPOST: RPGnet Newsletter #115

RPGnet Newsletter #115
November 7, 2017

SubFora You Might Have Missed

The last couple of weeks have brought several structural changes to the RPGnet Forums that we all know and love. Rather than look at particular threads, we’ll take a moment this week to describe the new and rearranged subfora.

The Starting Gate: New Player/GM Help provides a tightly-focused, friendly place for folks new to either RPGs in general or the majesty and wonder of GMing in particular to come for advice. Be sure to take a look at The Starting Gate Rules and Guidelines before diving in.

What was “Let Me Tell You About My Character” is now Let Me Show You What I Made, which is the now-broader subforum for showing off or collaborating on all of the brilliant homebrewed RPG characters, settings, and other creative endeavors that populate the RPGnet forums. [101] threads also belong here.

Speaking of brilliant creations, consider joining the new Cosplay and Crafts subforum to discuss, admire, and share all of your more physical creative endeavors.

New Columns

Two weeks means two new comics from Christopher Cecil for his Fuzzy Thinking series: “Child of Destiny” and “Bad Dice!”

Iustum offered anoter issue of his PbP-focused column Words on a Screen, this time offering advice on “Tips for Designing PbP Scenarios.”

Brent Dedeaux of Tales from the Rocket House continued his look at the mechanics of OSR games in: “Which Bonus Part 2: AC vs HP.”

New Reviews

Nick the Lemming reviewed the first “proper” Cthulhu Confidential scenario, “The House up in the Hills” and noted that it provides a promising start to the line.

Jacob DC Ross reviewed the “Doctor Who Solitaire Storytelling Game, Second Edition,” which brings new mechanics to the classic solo RPG.

Antonios S used his sensors on the “Star Trek Adventures Core Rulebook,” which has strong mechanics and good feel, but is not very newbie-friendly.

Continuing his trip throught the galaxy, Antonios also reviewed several accessory sets related to the base game:

Continuing with game accessories, Antonios reviewed the “Deep-Cut Studio Grass Wargame Terrain Mat (6′ x 4′, mousepad),” which is a super cool, kick-ass mat that will take care of all your plains, grassland and jungle needs.

Antonios also reviewed another expansion for the Campaign Cartographer 3 mapping software, “Tome of Ultimate Mapping 3+,” which expands on the basic material already in the program while keeping everything neat, tidy, and in the same place.

Continuing his look at Freebooter’s Fate sets, Antonios also looked at “Mercenaries (full crew),” which provides several options for filling out other crew lists with the titular characters.

Then, we had two dueling reviews of the vintage RPG Empire of the Petal Throne. StormBringer’s review noted the game’s similarity to Brown Box D&D and it’s friendliness to both new and old players. Haken Kirk’s review provides a more in-depth breakdown of the core book and its various features.

Then, Antonios S was back with a review of “Jeweled Thrones of the Earth,” a supplement to the Modiphius Conan RPG that shows how Conan stories are supposed to feel.

Jonathan Hicks reviewed new RPG “Gateway,” which has some flaws in presentation and lacks focus, but holds together as an introductory RPG.

Mario Magallanes took a look at Spanish RPG “La Puerta de Ishtar,” a well-written, workable game that is worth checking out for any Spanish readers with an interest in sword-and-sorcery or Meopotamian mythology.

Ben Riggs reviewed the “Legend of the Five Rings 5th Edition Beta Rules,” that may be too complex for reasonable play around the table.

Joe G Kushner wrote up a short review of Vallejo’s “Old & New Wood Effects,” which may help spruce up your miniatures.

Jonathan Hicks reviewed “Fanfare for the Chosen – An Exalted 3rd Edition Music Suite”,” and found it to be an excellent soundtrack for one of the most popular roleplaying games on the market.

Endzeitgeist took a look at “Pergamino Barocco,” a useful, system-agnostic booklet of spells that feel “occult.”

Endzeitgeist also reviewed “Better Than Any Man,” a module for the Lamentations of the Flame Princess (2e) RPG that contains some adult content, but may be the new high-water mark for LotFP modules.

Sign Off

Have a good week, everyone.

  • Iustum
    Newsletter Editor