question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

As with others of my modules, I think a “choose your path” option for this module would be great.

“default”

By default – aka, the regular import – a middle of the road approach should be offered that covers the majority of cases. As of today, this would be the current klona module, supporting Objects, Arrays, Dates, RegExps, Maps, Sets, all TypedArray variants (includes Buffer), and primitives, of course.

Using this mode will continue to look like this:

import klona from 'klona';

“full”

There will definitely be a “full” mode (name TBD) that does everything “default” does, but with these added features. I originally was going to publish klona with these features to start, but removed them since they don’t fit the 90% use case IMO.

Of course, this mode will be a bit larger (~400 bytes) and significantly slower than the current klonahowever it’ll still be faster than most contenders of the current benchmark & none of them offer these extra features.

Again, this is opt-in behavior & I’m a fan of being explicit about what you need and where you need it. Using this mode will look like this:

import klona from 'klona/full'; // name TBD

“lite”

There will also be “lite” or “json” mode (name TBD) for handling simpler cases. I actually think the 90% use case doesn’t bother with cloning RegExps, TypedArrays, or even Maps & Sets, but “default” included them to be safe.

The lite/json mode, as the name suggests, will handle far fewer cases than the “default” and “full” counterparts. Because of this, this mode will be ~200 bytes and the fastest of the three.

I’m still debating if this mode should handle RegExp and Date. If so, then the name would have to be “lite” – otherwise only valid JSON datatypes will remain, thus making “json” a clear & obvious choice for dealing with JSON data objects.

As with “full”, using this mode is an opt-in behavior and should be obvious when you’ve made that choice. Using this mode will look like:

import klona from 'klona/lite';
// ~ OR ~
import klona from 'klona/json';

Please leave any comments or concerns or naming suggestions that you may have. This is planned for a minor/feature release since nothing changes to the default mode.

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lukeedcommented, Feb 20, 2020

Thanks for the feedback 👍

In my mind, they’re entirely separate entry points – or alternate versions – of themselves. I contrast that with named exports (or any exports) which are the actions that the module is capable of.

In this case, it’s all the same action – just different flavors of it.

There’s also the benefit of reduced parsed/network cost. With ESM-in-production growing, the need to respect bytes over the wire or time-to-parse doesn’t suddenly disappear because you have a named export. You’d be juggling 700-850 bytes when you knew all you needed was 200.

Finally, I think naming is always a subjective thing. You can easily fall into the same predicament you’ve described by doing this:

import { full as klona } from 'klona';
// still requires that I knew "klona" === "full"

…or alias the multiple entries like this:

import klonaLite from 'klona/lite'

Either way, the dev is the one decidedly opting into a mode/version and has to keep its capabilities in mind. They can use whatever naming patterns they want to help serve as a reminder.

Does that sound reasonable?

1reaction
cbbfcdcommented, Mar 6, 2020

maybe as an optional param??:

import klona from 'klona';

klona(someObj, { mode: 'full' }); //default lite
Read more comments on GitHub >

github_iconTop Results From Across the Web

More Than One Mode | How To Find Mode In Math
There can be more than one mode in a list or set of numbers. Look at this list of numbers: 1, 1, 1,...
Read more >
How Do You Find the Mode of a Data Set?
The mode of a data set is the number that occurs most often, but what if your data set has more than one...
Read more >
Mode: What It Is in Statistics and How to Calculate It
The mode is the value that appears most frequently in a data set. A set of data may have one mode, more than...
Read more >
Can there be more than one mode?
A data set can often have no mode, one mode or more than one mode – it all depends on how many different...
Read more >
How to Calculate the Mode or Modal Value
3 appears three times, as does 6. ... Having two modes is called "bimodal". Having more than two modes is called "multimodal". Try...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found