meteor-astronomy

Model layer for Meteor
授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发、 JavaScript MVC 框架
软件类型 开源软件
地区 不详
投 递 者 强安和
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Astronomy for Meteor

The Astronomy package introduces the Model Layer into Meteor applications. It can also be named the Object Document Mapping system (ODM) or for people coming from relational database environments the Object-Relational Mapping system (ORM). Astronomy extends MongoDB documents with functionalities defined in a schema.

Documentation

Astronomy documentation can be found here.

Tutorials

You can learn more about Astronomy by watching video tutorials that I'm creating. I'm trying to add a new one every week. You can access them here https://goo.gl/9gnrav

Installation

$ meteor add jagi:astronomy

Support Astronomy development

I've decided to start Patreon page. If you enjoy using Astronomy and want to support development of future versions, then any donation will be welcome :).

Introduction

When fetching documents from Mongo collections, you get plain JavaScript objects without any logic. You have to validate values of objects' properties, check what fields have changed, save only modified fields, transform values coming from forms, in every place you are playing with a document; a lot of things to do. Wouldn't it be great if you could define some simple rules and leave everything else to framework? It's actually possible thanks to Astronomy. But first let's take a look at how your code would look like without using Astronomy.

var post = Posts.findOne(id);
// Assign values manually instead doing it automatically.
post.createdAt = new Date();
post.userId = Meteor.userId();
// Manually convert values coming from the form.
post.title = tmpl.find('input[name=title]').value;
post.publishedAt = new Date(tmpl.find('input[name=publishedAt]').value);
// Every time implement custom validation logic.
if (post.title.length < 3) {
  // Implement an error messages system.
  throw new Error('The "title" field has to be at least 3 characters long');
} else {
  // Detect what fields have changed and update only those.
  // Access collection directly.
  Posts.update({
    _id: post._id
  }, {
    $set: {
      title: post.title,
      publishedAt: post.publishedAt,
      createdAt: post.updateAt
    }
  });
}

With Astronomy and defined schema your code would look like follows:

// Notice that we call the "findOne" method
// from the "Post" class not from the "Posts" collection.
var post = Post.findOne(id);
// Auto convert a string input value to a number.
post.title = tmpl.find('input[name=title]').value;
post.publishedAt = new Date(tmpl.find('input[name=publishedAt]').value);
// Check if all fields are valid and update document
// with only the fields that have changed.
post.save();

What approach is simpler? I think the choice is obvious.

For clarity, here is a sample schema that allows that. May seem to be a lot ofcode but have in mind that you write it only once.

import { Class } from 'meteor/jagi:astronomy';

const Posts = new Mongo.Collection('posts');
const Post = Class.create({
  name: 'Post',
  collection: Posts,
  fields: {
    title: {
      type: String,
      validators: [{
        type: 'minLength',
        param: 3
      }]
    },
    userId: String,
    publishedAt: Date
  },
  behaviors: {
    timestamp: {}
  }
});

Supporters

Contribution

Bigs thanks for all the contributions in form of commits and bug reports. Without you it would not be possible to improve Astronomy. Special thanks to:

  • Faberle - for help with Meteor methods feature
  • Ben305 - for several PRs
  • peterchoo - for several PRs
  • talha-asad - for updating History of changes
  • all other commiters that I forgot to mention

If you have any suggestions or want to write new features or behaviors please contact me, or just create an issue or a pull request. If you found any error please create a reproduction repository and create an issue. Thanks to that it will be easier for me to tell what is wrong. Please, don't use CoffeeScript for creating a reproduction.

License

Astronomy is released under the MIT License.

  • Astronomy(天文学) 定义: The branch of physics that studies celestial bodiesand the universe as a whole. 衍生词: Astronomer 天文学家 Astronaut 宇航员 Astrology 占星术 Astrologer 占星家 Celestial body(天体) 恒星star 行星planet及其卫

  • http://www.csdn.net/article/2013-04-25/2815040-Best-Learning-Resources-for-Meteor.js http://blog.csdn.net/zeo112140/article/details/7816014

  • Blaze.render(模板,添加模板的标签); render用于绘制模板到DOM,其中第一个参数为模板,第二个参数是要将模板添加到的标签, <!-- 传输数据 --> <div id = "myContainer"> </div> <template name = "myNewTemplate"> <p>Text from my new template...</p> </temp

  • 先说明这里指的Meteor是IT领域内的,不是我们说的“流星”。     什么是Meteor? 它是移动端、web端、桌面应用的一个开源平台。 全球已经有50多万的开发者使用它快速、高效、稳定的制作javascript应用程序。     为什么使用Meteor? 1)整合你已经使用的技术。专注于构建应用特性,而不是关注连接应用组件。 2)为所有设备编译apps。无论是web、iOS、Android

  • allowtransparency="true" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?url=http%3A%2F%2Fwww.csdn.net%2Farticle%2F2013-04-25%2F2815040-Best-Learning-Resources-for-Meteor.

 相关资料
  • Meteor 是一组新的技术用于构建高质量的 Web 应用,提供很多现成的包,可直接在浏览器或者云平台中运行。

  • Angular-Meteor Compilers meteor-rxjs - The Angular Meteor Data solution AngularJS-Meteor The power of Meteor and the simplicity and eco-system of Angular Documentation and Getting Started Official web

  • 本文向大家介绍meteor 入门,包括了meteor 入门的使用技巧和注意事项,需要的朋友参考一下 示例 安装流星 在OS X和Linux上 从终端安装最新的官方Meteor版本: 在Windows上 在此处下载官方的Meteor安装程序。 建立您的应用程式 安装Meteor后,创建一个项目: 运行 在本地运行: 注意:流星服务器运行在:http:// localhost:3000 / 然后转到h

  • Meteor integration in NativeScript using nativescript-websockets $ tns plugin add nativescript-meteor-client To init your Meteor connection and classes add this snippet just after the platformNativeSc

  • 本文向大家介绍meteor 管理包,包括了meteor 管理包的使用技巧和注意事项,需要的朋友参考一下 示例 流星在atmomentjs.com上拥有自己的软件包存储库 您可以通过运行以下命令从大气中添加新软件包: 例如: 同样,您可以通过以下方式删除相同的软件包: 要查看项目中的当前软件包,请键入: 软件包列表也可以在文件中找到./meteor/packages。要添加软件包,请在此文件中添加软

  • Meteor的理念 Data on the Wire. Meteor不在网络上发送HTML。服务器发送数据,让客户端来渲染它。 One Language. Meteor使你可以用javascript来实现应用的客户端和服务端 Database Everywhere. 在客户端和服务端,你可以使用相同的方法来使用数据库。 Latency Compensation. 在客户端,Meteor 预加载数据