A simple DDD library by powerful. Design for Front-End to create Bounded Context Model.
A simple library for Front-End to create Bounded Context Model.
Bower:
bower install ddm
NPM:
npm install ddm
Usage:
var ddm = new DDM();
originObject = {
title: 'hello',
blog: 'fdsf asdf fadsf ',
author: 'phodal'
};
var newObject = {};
Basic Example:
ddm.get(['title']).from(originObject).to(newObject);
Result
{title: "hello"}
With Remove:
ddm.get(['title', 'blog', 'author'])
.from(originObject)
.remove('title')
.to(newObject);
Result:
{blog: "fdsf asdf fadsf ", author: "phodal"}
With Add:
ddm.get(['title'])
.from(originObject)
.add('tag', 'hello,world,linux')
.to(newObject);
Result:
{tag: "hello,world,linux", title: "hello"}
With Custom Handle:
function handler(blog) {
return blog[0];
}
ddm.get(['title', 'blog', 'author'])
.from(originObject)
.handle("blog", handler)
.to(newObject);
Result:
{title: "hello", blog: "A", author: "phodal"}
With Replace:
ddm.get(['title', 'blog', 'author'])
.from(originObject)
.replace("blog", "description")
.to(newObject);
Result:
{description: "fdsf asdf fadsf ", title: "hello", author: "phodal"}
对于我们的几个不同业务情景下,我们只使用同一个后台API的情形。如下图所示:
在我们的Blog Model里,我们有Author
、Title
、Slug
、Content
、Data
几个字段。
而在我们使用的时候,我们需要依据这个模型应用到不同的场景下:
Tag
、Title
、Author
、Date
、Content
五个字段。Tag
、Title
、Date
、基于Content
的Description
四个字段。Title
、Author
、Date
、Content
、Slug
五个字段。如果我们使用的是同一个模型,那么我们就很难做到分离上下文。并且在三种不同的场景下,Blog Model的含义都是不一样的。
于是,我们就需要想办法去区分不同的模型——这在后台来说是一件很容易的事。但是在前台谁想这样做?在这其中使用复杂的OO思想?
所以,我们有了DDM。
© 2016 Phodal Huang. This code is distributed under the MIT License. See LICENSE
in this directory.