Giter Club home page Giter Club logo

mock-data-models-poc's Introduction

mock-data-models-poc

POC for research generate mock data by models ( new Class)

Using classes, assign random functions or new other classes to attributes of instances, like :

function EventTemplate () {
	this.id = randomInt()
	this.event = new Event()
	this.name = 'Event Template'
}

Then use config like :

const oneAPIModelConfig = {
	id: Number,
	name: String,
	event: 'Event',
	template: 'EventTemplate',
	status: [Array, ['New', 'Approved', 'Deleted']],
	teams: ['Team', 10]
}

There are basic type and models generators. Number, String or so on are basic type ( of native javascript ). Event, EventTemplate are models( the classes defined by us ).

I registered all custom defined models to global. Then using the core.js and config json files, we can auto generate the mock data instances base on the types. And all the models are reusable, in different request/APIs, we don't need to rework for the exists models.

The logic of config values are:

Non-array:
	- The value is the type of current attribute, basic type are functions, Number, String and etc. Custom define models are in strings, `'Event'`, `'EventTemplate'` and etc.

Array:
	- First element is the type of current attribute
	- Rest elements are the arguments for generator of this attributes.
		-- If second element is number, means current attribute is an array, the number is the array length. Every value of this array is random under the type.
		-- If type is array, and the second element is array also, means current attribute will get a random value from the second element array.
		-- Otherwise, will just pass rest elememts as arguments to the generator of the type.

mock-data-models-poc's People

Contributors

bee0060 avatar

Watchers

James Cloos avatar  avatar

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.