{"action":"created","issue":{"url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/236","repository_url":"https://api.github.com/repos/jagi/meteor-astronomy","labels_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/236/labels{/name}","comments_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/236/comments","events_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/236/events","html_url":"https://github.com/jagi/meteor-astronomy/issues/236","id":123732579,"number":236,"title":"Astronomy 2.0","user":{"login":"jagi","id":1051229,"avatar_url":"https://avatars.githubusercontent.com/u/1051229?v=3","gravatar_id":"","url":"https://api.github.com/users/jagi","html_url":"https://github.com/jagi","followers_url":"https://api.github.com/users/jagi/followers","following_url":"https://api.github.com/users/jagi/following{/other_user}","gists_url":"https://api.github.com/users/jagi/gists{/gist_id}","starred_url":"https://api.github.com/users/jagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jagi/subscriptions","organizations_url":"https://api.github.com/users/jagi/orgs","repos_url":"https://api.github.com/users/jagi/repos","events_url":"https://api.github.com/users/jagi/events{/privacy}","received_events_url":"https://api.github.com/users/jagi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jagi/meteor-astronomy/labels/discussion","name":"discussion","color":"0000c8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":128,"created_at":"2015-12-23T22:40:15Z","updated_at":"2016-02-25T17:34:56Z","closed_at":null,"body":"I've started this issue to share progress on Astronomy 2.0. I wanted to release RC version before the end of this year but **it will be published before the end of Q1 in 2016**. I've rewritten almost entire package to make it faster (**23 times faster document initialisation**), less error prone and full-featured.\r\n\r\n**DEMO:**\r\nhttp://astronomy2.meteor.com/\r\n\r\n**CURRENT VERSIONS:**\r\n- `jagi:astronomy@2.0.0-rc.5`\r\n- `jagi:astronomy-timestamp-behavior@2.0.0-rc.2`\r\n\r\n**NEW FEATURES:**\r\n- [x] ES2015 compatible\r\n- [x] Direct collection/class access (support for all MiniMongo modifiers)\r\n- [x] New events system\r\n- [x] Improved events propagation for nested classes\r\n- [x] Better error reporting on invalid schema\r\n- [x] New modules system\r\n- [x] Automatic document modifications detection. Now you can modify your documents freely without using `set`, `push`, `inc` etc. methods. Astronomy will detect changes to your documents and try to perform minimal query\r\n- [x] Save and remove methods implemented as Meteor methods. No need to create your own Meteor method to perform operation in both environments (client & server) - just call `doc.save()` or `doc.remove()`\r\n- [x] Validate document on every save\r\n- [x] Support for ObjectIDs\r\n- [x] GraphQL ready (support for GraphQL in future Meteor releases)\r\n- [x] New validators system\r\n- [x] Add multiple behaviors of the same type to the one class\r\n- [x] Mapping field name to different field name in collection\r\n- [ ] Built in relations module with ability to fetch/populate related documents\r\n- [ ] ENUM type\r\n- [ ] Autoincrement fields\r\n\r\nThere are many new minor features that I will be adding to the list. There are also some changes to API about which I will be writing more soon. Astronomy 2.0 will also fix many bugs or problems from 1.0.\r\n\r\n**MAIN CHANGES IN V2 COMPARING TO V1:**\r\n- `Astro.Class.create` instead `Astro.Class`\r\n- Field type:\r\n```js\r\n// v1\r\nfields: {\r\n  firstName: 'string'\r\n}\r\n// v2\r\nfields: {\r\n  firstName: String\r\n}\r\n```\r\n- Nested field type:\r\n```js\r\n// v1\r\nfields: {\r\n\taddress: {\r\n\t\ttype: 'object',\r\n\t\tnested: 'Address'\r\n\t},\r\n\tphones: {\r\n\t\ttype: 'array',\r\n\t\tnested: 'Phone'\r\n\t}\r\n}\r\n// v2\r\nfields: {\r\n  address: Address,\r\n  phones: [Phones]\r\n}\r\n```\r\n- The `this` context in events is not document. Write `event.target` to get document in event. Write `event.currentTarget` to get nested document.\r\n```js\r\nevents: {\r\n  beforeSave: function(e) {\r\n    let doc = e.target();\r\n  }\r\n}\r\n```\r\n- You have to use `Class.find()` instead `Collection.find()` to find documents and transform them to instances of Astronomy class.\r\n- You don't have to use `set` to set values, you can modify document fields freely.\r\n```js\r\nvar user = new User();\r\n// v1\r\nu.set('firstName', 'John');\r\n// v2\r\nu.firstName = 'John';\r\n// however you can still write for nested fields\r\nu.set('address.city', 'San Francisco');\r\n```\r\n- `push`, `inc`, `pop` methods have been removed .\r\n- Changed the way how validators are defined.\r\n```js\r\nfields: {\r\n\tfirstName: {\r\n\t\ttype: String,\r\n\t\tvalidators: [{ // Single validator with the param\r\n\t\t\ttype: 'minLength',\r\n\t\t\tparam: 5\r\n\t\t}]\r\n\t},\r\n\tlastName: {\r\n\t\ttype: String,\r\n\t\tvalidators: [{ // Multiple validators with params and custom error message\r\n\t\t\ttype: 'minLength',\r\n\t\t\tparam: 2,\r\n\t\t\tmessage: 'Too short'\r\n\t\t}, {\r\n\t\t\ttype: 'maxLength',\r\n\t\t\tparam: 10,\r\n\t\t\tmessage: 'Too long'\r\n\t\t}]\r\n\t},\r\n\tbirthDate: {\r\n\t\ttype: Date,\r\n\t\tvalidators: [{ // Validator with the function that resolves to the param\r\n\t\t\ttype: 'lte',\r\n\t\t\tresolveParam: function() {\r\n\t\t\t\tlet date = new Date();\r\n\t\t\t\treturn date.setFullYear(date.getFullYear() - 18);\r\n\t\t\t}\r\n\t\t}]\r\n\t}\r\n}\r\n```\r\n- You don't have to write method for client and server to save a document. You can just write `doc.save()` on the client and the corresponding `doc.save()` method will be called on the server.\r\n```js\r\n// client.js file\r\nvar user = new User();\r\nuser.save(); // It will also save document on the server and trigger all the events and validation on the server\r\n```"},"comment":{"url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/comments/188894418","html_url":"https://github.com/jagi/meteor-astronomy/issues/236#issuecomment-188894418","issue_url":"https://api.github.com/repos/jagi/meteor-astronomy/issues/236","id":188894418,"user":{"login":"jagi","id":1051229,"avatar_url":"https://avatars.githubusercontent.com/u/1051229?v=3","gravatar_id":"","url":"https://api.github.com/users/jagi","html_url":"https://github.com/jagi","followers_url":"https://api.github.com/users/jagi/followers","following_url":"https://api.github.com/users/jagi/following{/other_user}","gists_url":"https://api.github.com/users/jagi/gists{/gist_id}","starred_url":"https://api.github.com/users/jagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jagi/subscriptions","organizations_url":"https://api.github.com/users/jagi/orgs","repos_url":"https://api.github.com/users/jagi/repos","events_url":"https://api.github.com/users/jagi/events{/privacy}","received_events_url":"https://api.github.com/users/jagi/received_events","type":"User","site_admin":false},"created_at":"2016-02-25T17:34:56Z","updated_at":"2016-02-25T17:34:56Z","body":"@talha-asad Every thing is in the documentation ;-)\r\n\r\nI won't mess with the `save()` method for state changes as it does not the point. It's not about the save method it's about the state of document. It may not necessarily be related with saving. You may need changing document state regardless of that. So it will be something different."}}