mattmaynes / pyjamas-js Goto Github PK
View Code? Open in Web Editor NEWVersioned Persistable JavaScript - Keep your code cozy
License: MIT License
Versioned Persistable JavaScript - Keep your code cozy
License: MIT License
The complexity of the decode function is 7. This is too damn high! The logic for upgrading can be abstracted to its own function which will reduce the complexity.
https://codeclimate.com/github/mattmaynes/pyjamas-js/src/pyjamas.js#all
/**
* Returns a JSON string representation of a target instance
*
* @param target {object} Target object to serialized
*
* @return {string} JSON string representation of target
*
* @see Viper.manifest
*/
Viper.toJSON = function(){
...
};
/**
* Given a string representation of a version, convert the version
* to a 3 element array
*
* @param version {string} A version identifier
*
* @return {Array<int>} [major, minor, patch] Version array
*/
function split (version){
...
}
When an object is being constructed the upgraders need to be applied incrementally to the newly constructed object. This should probably done in a reduce operation
Move the invocation into the parens that contain the function.
Move the invocation into the parens that contain the function.
Move the invocation into the parens that contain the function.
At times your constructor may require dependencies on other objects. Because of this if your constructor is called while these dependencies are not yet loaded, there will be issues. If an option could be made to attach the prototype and necessary attributes to the object without calling the constructor, this would be a good solution to this problem.
ie:
class MyClass {
constructor() {
this.test = Resource.getVal(1);
}
}
This is a trivial example, but here we know that test is a defined value and we do not need to call the constructor to construct this object (in case Resource has not yet been defined)
This should be a functional implementation that takes an object and returns a deep copy of the object with an added version tag. The return should be JSON persistable (i.e. no undefined members, no functions, etc.)
/**
* Manifests an instance of a class as a bare-bones object that confirms
* to JavaScript Object Notation. The resulting object will have no
* undefined fields, functions or a constructor. There are no references
* to the original constructor stored. It is up to the user to keep the
* association of the return the type class definition of the manifested
* object.
*
* @param target {object} Target object to manifest
*
* @return {object} Versioned persistable representation of target
*/
Pyjamas.manifest = function (){
...
};
Pyjamas currently only supports major.minor.patch versions but there are many other versioning variations available. There should be a generic way to specify a version format
/**
* Removes a class from the PyjamasDB if it exists, otherwise return null
*
* @param constructor {function} Object constructor to unregister
*
* @return {Pyjamas | null} Removed Pyjamas instance or null if the constructor
* was not registered
* @end
*/
Pyjamas.unregister = function (){
...
};
Currently Pyjamas supports extending a single registered Pyjamas instance to have one parent. We should be able to extend multiple parents into a signal child.
Pyjamas.register(MyClassA, '0.1.0', {
a : String,
b : Number,
c : Object
}).extend(MyClassB).extend(MyClassC);
Here the parent of MyClassA will only be MyClassC. We want both MyClassB and MyClassC to be parents of MyClassA.
Should register a class as a version-able instance. Should return a "Pyjamas object" or something that allows you to add version upgraders.
/**
* Registers a class into the PyjamasDB and returns a new Pajamas instance
*
* @example
* Pyjamas.register(MyClass, '0.1.2', {
* foo : Number,
* bar : String,
* baz : MyOtherClass
* });
* @end
*
* @param constructor {function} Object constructor to register
* @param version {string} Current version of object constructor
* @param defines {object} Definitions of instance variables to
* persist when given an instance of the constructor's class
* @end
*
* @return {Pyjamas} A new viper instance
*/
Pyjamas.register = function (){};
If you try to execute Pyjamas.construct(MyObject, json)
where MyObject contains another registered object, and json does not contain a reference to that object, an error is thrown at line 463 when trying to index into the object.
ie:
Pyjamas.register(MyOtherObject, '0.0.1', { z: String });
Pyjamas.register(MyObject, '0.0.1', { x: MyOtherObject, y: String });
// This will cause an error, because it will try to index into 'x' (undefined) to get values
var ob2 = Pyjamas.construct(MyObject, { y: "test" });
Error: Cannot read property 'z' of undefined
Should accept a class constructor and a raw object which we need to use to populate a new instance of the given class. If the class has any registered "version upgraders" then they should be applied to the new instance.
/**
* Reconstructs a persisted object as an instance of the given constructor.
* If the given target is not at the current version of the constructor then
* upgraders will be successively applied until the highest version is
* achieved.
*
* @param constructor {function} Object constructor
* @param target {object} Raw instance to use to populate
* a new instance of the constructor
* @end
*
* @return {object} A new instance of the constructor
*/
Pyjamas.construct = function (){
...
};
The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
https://codeclimate.com/github/mattmaynes/pyjamas-js/src/pyjamas.js#issue_56eeff6c8a516900010b0d34
Missing radix parameter.
https://codeclimate.com/github/mattmaynes/pyjamas-js/src/pyjamas.js#issue_56eeff6c4a1a780001088f53
Move the invocation into the parens that contain the function.
Commits should be failed if they break the test fixtures.
The karma test specification has grown to be unmaintainable. It needs to be split into multiple files for each major feature.
/**
* Returns the difference between two version numbers. This is a
* pairwise comparison of each element in the version identifier.
*
* @param base {string} Base version
* @param other {string} Version to compare to
*
* @return {Array<int>} A pairwise comparison of each version number
*/
function diff (base, other){
...
}
/**
* Registers an upgrade function to this viper instance. An upgrade function
* must accept a copy of a old version of a save and the current instance.
* It should either mutate the current instance of the save or return an
* upgraded version.
*
* @param version {string} Version code that indicates the version of the
* instance returned from this upgrade function
* @end
*
* @param upgrader {function} Function to upgrade old save. Prototype:
* function( old : Object, current : Object) : Object
* @end
*
* @return {Pyjamas} An updated Viper instance
*/
Pyjamas.prototype.upgrade = function(){
...
};
Move the invocation into the parens that contain the function.
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.