Giter VIP home page Giter VIP logo

scheming's People

Contributors

andrew-goldstein avatar blu-j avatar erin-noe-payne avatar nicholasboll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scheming's Issues

Defaulted boolean to `false`, on instantiation is set to `true`.

Given a schema that defaults a boolean property the instantiated (with non-provided value) appears to be getting set to 'true'. This is using v0.1.3

Code:

var Scheming = require('scheming');


var Bool = Scheming.create("Bool", {
    isRoot: {
        type: Boolean,
        "default": function() {
            return false;
        }
    }
});


var b = new Bool();
console.log("isRoot s/b 'false', but it is: ", b.isRoot);

Result:

isRoot s/b 'false', but it is:  true

uuid not _exactly_ correct

The UUID's are not exactly correct.

From wikipedia:
http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29

Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B (e.g., f47ac10b-58cc-4372-a567-0e02b2c3d479).

However, when running the uuid method several times it will return more letters than 8, 9, A, or B for the "y" value.

The line here:

((if c is "x" then r else (r & 0x7 | 0x8))).toString 16
https://github.com/autoric/scheming/blob/master/src/Scheming.coffee#L20

should have the 0x7 replaced with 0x3

like so

((if c is "x" then r else (r & 0x3 | 0x8))).toString 16

I got that from what looks like very similar code from:
http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript

I think this was a type-o from lifting the original?


I would fork and make a pull request but I'm lazy.

Get .valueOf error for defaulted date Schema

Here's the code that breaks:

var Scheming = require('scheming');

Stuff = Scheming.create("Stuff", {
    createdOn: {
        type: Date,
        "default": function() {
            return Date.now();
        }
    }
});

new Stuff()

Produces this error:

TypeError: Cannot call method 'valueOf' of undefined
    at Object.TYPES.Date.equals (/Users/lucas.caballero/tmp/break-scheming/node_modules/scheming/dest/Scheming.js:84:18)
    at set (/Users/lucas.caballero/tmp/break-scheming/node_modules/scheming/dest/Scheming.js:569:19)
    at Schema.Object.defineProperty.set [as createdOn] (/Users/lucas.caballero/tmp/break-scheming/node_modules/scheming/dest/Scheming.js:718:20)
    at /Users/lucas.caballero/tmp/break-scheming/node_modules/scheming/dest/Scheming.js:725:37
    at instanceFactory (/Users/lucas.caballero/tmp/break-scheming/node_modules/scheming/dest/Scheming.js:731:7)
    at new Schema (/Users/lucas.caballero/tmp/break-scheming/node_modules/scheming/dest/Scheming.js:454:9)
    at Object.<anonymous> (/Users/lucas.caballero/tmp/break-scheming/break.js:14:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

I'm guessing it's trying to determine if the value has changed (per 'reactive' programming), but the value is never assigned and so it is 'undefined'. Then calls to .valueOf() method are made during the comparison test which throws this error.

Update documentation to state that Scheming.TYPES.Mixed '*' may be used to model an object with arbitrary properties

Update the documentation (README) to state that Scheming.TYPES.Mixed '*' may be used to model an object with arbitrary properties. For example, if you wanted to create a Foo model that contains two properties:

name | String | The name of this foo instance, which may be null                                                                                 
bar  | Object | An initially empty object that will later have additional properties arbitrarily assigned to it

you could model it as:

Foo = Scheming.create 'Foo',
  name :
    type    : String
    default : null
  bar  :
    type    : "*"
    default : {}

IMPORTANT: If you .watch() an instance of the model above, the watcher will fire if the reference to bar changes (e.g. if you assigned a different object to the bar property), however, changes to the properties of bar itself (e.g if you arbitrarily assigned a new property to bar), will NOT fire the watch.

Default values share a reference

Given a model with a default value, that default is a shared reference between all model instances.

Example:

Model = Scheming.create({
  foo : {
    type : '*',
    default : {}
  }
});

m1 = new Model();
m1.foo.a = 7;

m2 = new Model();
console.log(m2.foo.a); //7

Current workaround is to set default to a function that returns a default value.
Need to investigate if the shared reference behavior is useful or a bug. If a bug, need to defensively copy default values.

Modify array functions & document for change tracking

Should overwrite array manipulators and document

  • Array mutations must be clone and assign
  • Comparison via _.equals between a scheming instance and a plain object will fail because they have different constructors, even if all kvp are the same.

Getting instance properties/values

Is there a way to get the properties and values of an instance as an object without explicitly calling each property?

I can get them by doing something like this:

newUser = new User({email: '[email protected]'})
userObject = User.getProperties()
params = {}
_.each userObject, (value, key) ->
  params[key] = newUser[key]

But I would love it if there was a method on the instance to do that. Does that exist and I just missed it?

Lodash is included in browser output

The project has a bower dependency on lodash, but also includes lodash with the output. Using something like bower-main-files means lodash will get included more than once.

This takes the minified output from 18K (without lodash) to 70K. That is a significant amount extra to send to a browser (especially mobile). The build should not include lodash in the output and have a bower dependency as it does now.

gulp deploy task

write a gulp deploy task or otherwise tie into npm version command so that version strings are kept in sync across npm, bower, and package.json / bower.json

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.