js.component: Taking 4D to the next level – Aparajita Fishman

Wednesday, March 2, 2022, 12:00 noon, CST (UTC−5:00)

Special Topic:
js.component: Taking 4D to the next level – Aparajita Fishman

4D has taken a lot of steps towards modernizing the language with v19, but there is other functionality that is taken for granted in the JavaScript world but missing in 4D — until now.

js.component a pure 4D component comprising 30 classes with over 400 functions that:

  • Dramatically improves the developer experience
  • Reduces method count, lines of code, and coding time
  • Provides multiple, super-convenient ways of debugging code
  • Fills in many holes in the 4D language
  • Implements key object-oriented techniques that are mostly unknown in the 4D world

js.component consists of:

Inspired by the king of all JavaScript utility libraries, lodash, this single class dramatically improves the 4D language and will save you countless lines of code. You won’t want to code without it!

How many times have you wished we had a unified date/time class? Now you do! js.component’s DateTime class provides a complete object-oriented wrapper around all of the 4D date and time functionality, and adds much more functionality that 4D does not have:

  • Create a single object which encapsulates, date, time, and milliseconds
  • Retrieve constituent parts: year, month, day, weekday, hours, minutes, seconds, milliseconds, and time zone offset!
  • Add/subtract DateTimes, days, hours, minutes, seconds
  • Compare DateTimes
  • Format as a string with complete control over the formatting (see https://github.com/taylorhakes/fecha#formatting-tokens)
  • Set named custom formats
  • Internationalize month/day/weekday/am/pm

There is a whole class of problems that regular expressions solve extremely well. js.component makes 4D’s Match regex command 100x more useful:

  • _.regexMatch() returns a collection of matches and capture groups. No more legacy arrays.
  • _.regexReplace() implements the complete JavaScript String.replace() with regex functionality, including using replacement placeholders or a replacer function.
  • _.regexSplit() lets you split strings using a regex. A multi-line parsing loop can be reduced to a single line of code.

Need to know when some operation has timed out? It’s as simple as this:

Wouldn’t it be great to have a single class that encapsulated everything about an error? The Error class not only encapsulates the current error state, it also intelligently captures the call stack.

How many times have you wanted to measure the performance of a chunk of code? The Performance and Timer classes make it dead simple.

In the world outside of 4D, logging is an integral and essential part of both debugging your code and auditing runtime behavior. js.component features a 90% feature-complete port of the most popular JavaScript logging package, winston.

You write lots of code, but how can you be sure it works as designed? How do you test all of the code paths in a reproducible way? And how to you ensure that code changes don’t break the expected behavior?

In the non-4D world, test frameworks which do all of these things are not only the norm, they are more or less a requirement. js.component features a 90% feature-complete port of one of the most popular JavaScript testing frameworks, mocha, and one of the most popular assertion libraries, chai. Automated testing is now available to us!

A key object-oriented technique is the use of singletons: global instances of a class that are guaranteed to be unique and are easily accessible.

4d.js makes creating, registering and accessing singletons as simple as a single method call. In fact, much of what js.component provides is done through the magic of singletons.

Object-oriented techniques
In addition to singletons, there are a number of key object-oriented techniques that js.component both facilitates and demonstrates, including:

  • Composition
  • Delegation
  • Dynamic class function generation
  • Function binding
  • Functors
  • Introspection

This meeting is being hosted live with real-time discussion on Zoom.  Click here to join…

To follow along with the meeting slideshow, access it here when it is available…
Slides for March 2, 2022 meeting

Have comments or questions after the meeting?  Either post them here or to discuss.4d.com.

If you cannot attend the live Zoom meeting, don’t worry!  A recording will be posted to the 4DMethod Youtube channel after the meeting ends.

This entry was posted in Meetings and tagged , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

1 Response to js.component: Taking 4D to the next level – Aparajita Fishman

  1. Pingback: March 16th Meeting – js.component: Part 2 – Aparajita Fishman | 4DMethod – 4D User Group

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.