werehamster / avers-js Goto Github PK
View Code? Open in Web Editor NEWA model abstraction library
Home Page: https://werehamster.github.io/avers-js/
License: MIT License
A model abstraction library
Home Page: https://werehamster.github.io/avers-js/
License: MIT License
When a variant property changes we need to return two operations, one to change the type and another one to change the content.
Instead of using a global Object.observe()
callback, store it in the object that is being observed (under a private property). Then provide Avers.flushChanges(obj, recursive)
to flush changes of a specific object.
I consider it a bug in the parser if it crashes when it can't decode a variant property. It should instead set the property to null. migrateObject
can then take care of setting it to the default value if one is provided.
Now that we've moved aversProperties
to a private property and no longer expose it to users of the library, we should consider the same with event functions (on
, listenTo
, trigger
etc).
We can expose the event functions through the Avers
module. However, they create an _events
property which is used to store callbacks that are attached to the object. What I have in mind is to store them in a WeakMap
instead. It would probably have a small performance impact. Will need to benchmark it.
We have all the information about the properties in this._modelProperties. Use that to parse the JSON and assign values.
This might not always be possible, eg. when a property has a polymorphic type. Provide hooks so that derived classes can override the parser.
Use ES6 Symbols for that.
There is a typo in README.md
:
Typo: At this date (5015-07-18) only Chrome supports Object.observe.
Avers.define*
functions will get a new optional argument which will be used as the default value. The absence of the optional argument will make the field nullable. If a default value is provided and the field is null, then Avers.migrateObject
will initialize the property with a clone of the default value.
TODO: figure out what to do for variant properties.
Examples:
// Primitive property:
var default = 'default value';
Avers.defineProperty(Foo, 'field', default);
// Object property:
var default = Avers.mk(Bar, { test: 'one' });
Avers.defineObject(Foo, 'field', Bar, default);
// Variant property:
var default = Avers.mk(Bar, { test: 'one' });
Avers.defineVariant(Foo, 'type', 'content', { bar: Bar, baz: Baz }, default);
fetch()-initiated requests can be aborted: fetch(url).then(req => { req.cancel(); })
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.