Giter VIP home page Giter VIP logo

catberry's Introduction

Catberry

Build Status codecov.io Gitter

What the cat is that?

Catberry was developed to help create "isomorphic/Universal" Web applications.

Long story short, isomorphic/universal applications are apps that use the same codebase on both the server and client environments to render what the client would see as a "Single Page Application".

TLDR;

Install Catberry CLI using following command:

npm install -g catberry-cli

Use Catberry CLI to create an empty project with Handlebars support like this:

catberry init empty-handlebars

Or an example application that works using GitHub API:

catberry init example

Also, you can get a list of all templates:

catberry init ?

Useful links

Why should I use that?

Architecture

Rendering

For more details please proceed to Catberry Documentation.

Typical Cat-component example

'use strict';

class CoolComponent {

	/**
	 * Creates a new instance of the "CoolComponent" component.
	 * @param {ServiceLocator} locator The service locator for resolving dependencies.
	 */
	constructor(locator) {
		// you can resolve any dependency from the locator.
	}

	/**
	 * Gets data for the template.
	 * This method is optional.
	 * @returns {Promise<Object>|Object|null|undefined} Data for the template.
	 */
	render() {
		return this.$context.getStoreData();
	}

	/**
	 * Returns event binding settings for the component.
	 * This method is optional.
	 * @returns {Promise<Object>|Object|null|undefined} Binding settings.
	 */
	bind() {
		return {
			// CSS selector
			'.clickable': () => window.alert('Ouch!');
		}
	}

	/**
	 * Cleans up everything that has NOT been set by .bind() method.
	 * This method is optional.
	 * @returns {Promise|undefined} Promise of nothing.
	 */
	unbind() {
		// nothing to do here we have used bind properly
	}
}

module.exports = Some;

The component is used as a custom tag:

<cat-cool id="unique-value" cat-store="group/CoolStore"></cat-cool>

Typical Store example

'use strict';

class CoolStore {
	/**
	 * Creates a new instance of the "CoolStore" store.
	 * @param {ServiceLocator} locator The service locator for resolving dependencies.
	 */
	constructor(locator) {

		/**
		 * Current universal HTTP request for environment-independent requests.
		 * @type {UHR}
		 * @private
		 */
		this._uhr = locator.resolve('uhr');

		/**
		 * Current lifetime of data (in milliseconds) that is returned by this store.
		 * @type {number} Lifetime in milliseconds.
		 */
		this.$lifetime = 60000;
	}

	/**
	 * Loads data from a remote source.
	 * @returns {Promise<Object>|Object|null|undefined} Loaded data.
	 */
	load() {
		// Here you can do any HTTP requests using this._uhr.
		// Please read details here https://github.com/catberry/catberry-uhr.
	}

	/**
	 * Handles an action named "some-action" from any component or store.
	 * @returns {Promise<Object>|Object|null|undefined} Response to the component/store.
	 */
	handleSomeAction() {
		// Here you can call this.$context.changed() if you're sure'
		// that the remote data on the server has been changed.
		// You can additionally have many handle methods for other actions.
	};
}

module.exports = Some;

Browser Support

While Catberry is capable of rendering pages for any browser on the server, due to the use of certain HTML5 features, like the History API, only partial support of old browsers is possible for the client-side JavaScript application.

The main goal of the Catberry Framework is to use the full power of new technologies and provide a user with the best possible experience.

In fact, a user gets an HTML page from the server only once and all the rest of the time the whole page is changing in a browser receiving only pure data from API service(s) used with the application.

Thanks to Catberry's progressive rendering engine, user receives a page from the server component by component as fast as each component renders its template not waiting for the whole page is built.

Catberry supports 2 last versions of modern browsers and IE 11. It depends on Babel babel-preset-env preset which config you can override putting a .babelrc file in your project.

Contributing

There are a lot of ways to contribute into Catberry:

Denis Rechkunov [email protected]

catberry's People

Contributors

chetverikov avatar designeng avatar fornever avatar hisohito avatar jughosta avatar mansur-gabidullin avatar mass3ff3ct avatar rdner avatar reenko avatar reflog avatar vaseker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

catberry's Issues

Add assets building on catberry startup

Add basic assets building using gulp.

Every module has templates and some resources which need to process (copy, replace URLs, minify etc) and publish.

Catberry must execute all required gulp tasks.

Add profiles support for templating

Add profiles support to be able to implement different templates for several types of devices (smartphones, tables, desktop and etc) by their screen sizes.

Bundle creation problems on windows

As @dentrifonov reported
When start catberry on Windows get something like this:

[2014-05-25 16:56:17.443] [ERROR] catberry - { [Error: module "........catberry_modulesmainindex.js" not found from "C:\\Users\\Denis\\Documents\\Projects\\sample\\webapp\\node_modules\\catberry\\lib\\client\\__bundle_entr
y.js"]
  filename: '........catberry_modulesmainindex.js',
  parent: 'C:\\Users\\Denis\\Documents\\Projects\\sample\\webapp\\node_modules\\catberry\\lib\\client\\__bundle_entry.js' }
Error: module "........catberry_modulesmainindex.js" not found from "C:\\Users\\Denis\\Documents\\Projects\\sample\\webapp\\node_modules\\catberry\\lib\\client\\__bundle_entry.js"
    at notFound (C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\index.js:811:15)
    at C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\index.js:761:23
    at C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\node_modules\browser-resolve\index.js:185:24
    at C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\node_modules\resolve\lib\async.js:44:14
    at process (C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\node_modules\resolve\lib\async.js:113:43)
    at C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\node_modules\resolve\lib\async.js:122:21
    at load (C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\node_modules\resolve\lib\async.js:54:43)
    at C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\node_modules\resolve\lib\async.js:60:22
    at C:\Users\Denis\Documents\Projects\sample\webapp\node_modules\catberry\node_modules\browserify\node_modules\resolve\lib\async.js:16:47
    at Object.oncomplete (fs.js:107:15)

Implement event routing

Every hashtag change on page should raise an event in related modules and when change to another raise "end" event.

Add URL translator for human understandable URLs

Because of catberry modules receive its state from URL query string need to implement some kind of translator with URL mapping.

For example:

/rubrics?page=1

map to

/index?index_tab=rubrics?index_page=1

Simplify CookiesManager

Now CookiesManager support read/write operations but can be used only for read access. Need to remove all unused functionality and improve usability.

Advanced event routing

Now every event on page should change URL hash. It is very useful for links sharing when you need to restore the same page state by link but in some situations events are just client-side events and not need to share it via links.

In this case it is needed to handle link clicks as just events without hash changes if "a" tag has data-event attribute.

Add support for head tag as placeholder

It is needed to filter content when render head element placeholder.
We can not update script and link tags because it causes javascript re-execution and style re-applying.

Implement client-side placeholder rendering

One of key features of catberry will be isomorphic module implementation: one module will work at server-side and client-side.

Therefore need to implement client-side part of framework for placeholder rendering and module API support.

Replace SAX with own light-weight parser

SAX parser is too complicated and slow for Catberry. It has too much functionality which Catberry does not need.

It will be a huge performance improvement to replace it with own simple parser which just search for HTML tags with ID attribute and raise event when it has found it.

Also need to implement pause/resume functionality or make this parser a stream.

ParserDuplex works incorrect with HTML comments

When placeholder has HTML comments that end at the end of file it causes exception:

catberry/lib/server/streams/ParserDuplex.js:242
            var tag = String.concat(this._tagBuffer,
                             ^
TypeError: Object function String() { [native code] } has no method 'concat'
    at PlaceholderTransform.ParserDuplex._parseTokens (/Users/pragmadash/Projects/flamp/node_modules/catberry/lib/server/streams/ParserDuplex.js:242:21)
    at PlaceholderTransform.ParserDuplex._write (/Users/pragmadash/Projects/flamp/node_modules/catberry/lib/server/streams/ParserDuplex.js:107:7)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at PlaceholderTransform.Writable.write (_stream_writable.js:183:11)
    at write (_stream_readable.js:583:24)
    at flow (_stream_readable.js:592:7)
    at _stream_readable.js:560:7
    at process._tickCallback (node.js:415:13)

Request context storage

Implement something like context provider which can save some data per one request process. Main goal is to reuse data of one rendering process in another one.

Add universal http request implementation for modules

It is very useful to have http(s) request implementation for both client and server usage in modules. This new feature is called UHR (Universal HTTP request) and will be accessible for all modules via dependency injection and service locator.

Improve error handling when rendering page

Now any error in module stops page rendering on server-side. This is bad, it should only show error in placeholder where was error but whole page should be loaded on client.

Error handling should be the same on client and server and work in 2 modes:
Debug - all errors are shown with details and stack
Release - no errors are shown only special __error template or nothing.

Add base module implementation

Need to have ModuleBase constructor and userland modules should inherit ModuleBase.

ModuleBase should have:

  • Auto render methods support (if placeholder name is such-wow-placeholder then render method renderSuchWowPlaceholder should be invoked)
  • Auto handle methods support (same for events)
  • Auto submit methods support (same for forms)

Add method for testing browser support

Add to catberry object such method that checks browser support for ECMAScript 5 and History API.

It will be used for "Please update your browser page"

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.