Skip to content

Releases: sylvainpolletvillard/ObjectModel

v4.4.0

01 Nov 19:26
Compare
Choose a tag to compare
  • Improved a lot the TypeScript definitions for all models - looking for feedback/reports
  • Removed FunctionModel#extend: this method has never been properly documented and was not intuitive to use

v4.3.0

22 Jul 10:09
Compare
Choose a tag to compare
  • Performance improvement: every autocasted model now bypass its second validation step
  • Added a CHECK_ONCE mode as a second argument to object models constructors, that only validates the data once at model instanciation:
const Address = Model({ city: String, street: { name: String, number: Number }})
const a = new Address({ city: "Paris", street: { name: "Champs-Elysees", number: 12 }}, Model.CHECK_ONCE)

This feature has been asked to deal with specific performance issues, in situations where disabling ObjectModel completely is complicated or not desirable. This is not supposed to be a common usecase.

v4.2.0

13 May 22:06
Compare
Choose a tag to compare

Due to several issues raised after CJS build has been removed in v4, a CJS version of ObjectModel will be automatically generated thanks to https://www.npmjs.com/package/cjyes by @developit

v4.1

18 Mar 19:22
Compare
Choose a tag to compare
  • remove getPrototype proxy trap on object models, which should improve interoperability with other libraries
  • upgrade dependencies
  • minor perf improvements

v4.0

17 Jun 13:47
Compare
Choose a tag to compare

Breaking changes in v4

  • Node 6-7 support dropped. Long term support has officially ended on 2018-04-30.
  • UMD build dropped in favor of ESM builds exclusively. See explainations below.
  • Browser support is the same than v3, but you will have to bring your own transpiler. See explainations below.
  • REWORK defaults assignment: defaults for object models are no longer assigned to the model prototype, but applied only once at model instanciation, and now work for nested properties default values. This change aims to make default values behaviour more intuitive because using the prototype was too confusing for many users (I received many questions about it). To get the original behaviour, manually assign the default values to the model prototype.
  • API cleanup: removed ObjectModel defaults method. With the rework of defaults assignment, the distinction between defaults and defaultTo is no longer needed, so you can replace all defaults() calls with defaultTo() instead.
  • API cleanup: removed Model validate method, in favor of a second optional argument for the test method. Explaination: #96
  • API cleanup: removed the params argument to Model and ObjectModel constructors ; can be replaced with Object.assign
  • MOVED sealed object models to their own external models (see examples/sealed.js). This reduces the size of the library for users that don't use sealed models.
  • REMOVED the numberOfArgs assertion that was bundled with all function models. Explaination: #108

New features

  • Any
  • Any.remaining

Read the docs here

Moving from UMD to ESM

ObjectModel used to be distributed in both ESM (EcmaScript Module) and UMD (Universal Module Definition) format. ESM provide several advantages over UMD:

  • you can import only the features you need, and get a smaller library size penalty
  • modules run in strict mode by default, which covers more potential errors
  • globals are dangerous because they can be overridden by other libs, user scripts or browser extensions
  • AMD and other asynchronous module formats are basically dead now that dynamic import() is standard

In 2019, modern browsers now support natively ESM, and older browsers can still be supported through bundling tools like Webpack, Parcel or Rollup.

Therefore, starting from v4, ObjectModel will be exclusively distributed in ES module format. You should import what you need from the library like this:

import { Model, ObjectModel, ArrayModel } from 'objectmodel'

Some may consider this move to be too early, but there is technically no more argument in favor of UMD today, and legacy codebases can still use bundler tools or manually insert an UMD wrapper if needed. If you just want the ObjectModel API exposed as global variables like before, although I won't personally recommend it, this can be easily done with:

<script type="module">
	import * as globals from "./dist/object-model.js"
	Object.assign(window, globals)
</script>

Please consider switching to ES Modules for all your JavaScript projects if not done already.

Bring your own transpiler

In previous builds of ObjectModel, all the JS code transformations required to support older browsers were included in the distributed files, so that you could directly use the library and get maximum browser support. However, this came at a price: modern browsers had to suffer size and performance penalties due to useless transformations only required for older browsers support.

Therefore, starting from v4, ObjectModel is distributed in the latest version of the ECMAScript standard, with no consideration for code transforms used to improve the browser support. It will be your responsibility to configure a transpiler on your project for this purpose. The most popular option, and my personal recommendation, would be babel and @babel/preset-env.

This decision is motivated by these arguments:

  • it seems unfair to impose the same size and perf penalties on all projects, even those targeting a smaller set of modern browsers.
  • this fits logically with the decision to only distribute ESM builds, since you will have to configure a build step to support older browsers
  • transpilers in 2019 are a very common part of every web dev's toolkit, and included by default in most modern JS frameworks

As always, if you are unhappy with these changes, feel free to stick with an older version of ObjectModel which will continue to receive bugfixes.

Roadmap and public proposals

Since this library is starting to get some traction, I try to make its evolution more participative. New features and breaking changes in v4 have all been introduced as proposals in github issues, open to public discussion and feedback for a few months. I also look at open source projects using ObjectModel to see how it is being used and how could I improve the lib for them. As a reminder, there is a Gitter channel if you want to ask me questions or discuss about ObjectModel in a way that does not justify opening a issue on Github.

v3.7

21 Aug 16:39
Compare
Choose a tag to compare
  • Huge performance improvements for model instanciation and autocast (~4x faster)
  • Autocast no longer works for Basic Models. This is a very specific usecase and you should not be impacted
  • Improvements to TypeScript definition file

v3.6

01 Aug 21:27
Compare
Choose a tag to compare
  • share model code between all list models: ArrayModel, MapModel and SetModel
  • autocast ArrayModel items at model instanciation
  • check if Map and Set models constructor argument is iterable
  • added Array.prototype.fill and Array.prototype.copyWithin to ArrayModel mutator methods
  • add autocast to Array.prototype.fill method

v3.5

15 Jun 18:55
Compare
Choose a tag to compare
  • Object models now require passed values in constructor to be objects or inherit from objects. Primitives that could be casted to objects that meet the definition are no longer accepted. Closes #74

v3.4

30 Mar 22:11
Compare
Choose a tag to compare
  • Add Model.Name for debugging purposes with custom devtool formatters

v3.3

11 Mar 17:52
Compare
Choose a tag to compare
  • added support for <script type="module"> and direct use of ES6 modules in supported browsers
  • internal methods are now exposed as Symbols
  • improved library TS definition file
  • reduced the number of internal dependencies