Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into examples
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
#	Core.js
  • Loading branch information
DefeNder93 committed Apr 5, 2022
2 parents 1e41184 + c6a7de8 commit b78ab90
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.DS_Store
.package.json.swp
/node_modules/
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

### Core 0.1.10

- Enhanced typescript support to make it easier to create type definitions for Core Events and Requests.

### Core 0.1.9

- Added a special check to the processObject method to make sure it does not process constructor methods which is an issue
for some cases when Javascript precompilers which add constructor as a enumerable property to classes.

- Added a licence file (MIT)

### Core 0.1.8

- Added support for @types for Typescript.
11 changes: 6 additions & 5 deletions Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,10 @@ Core = {
}
for( var method in _class ) {
var events;
var isConstructor = method === 'constructor'; // some precompilers add constructor as a enumerable property which causes side-effects in Core
var isGetter = _class instanceof Object && Object.getOwnPropertyDescriptor(_class, method) && Object.getOwnPropertyDescriptor(_class, method).get;
// check if property is actually getter to prevent getters from calling (it can be js errors because of calling)
if (!isGetter && _class[method] instanceof Function ) {
if (!isGetter && _class[method] instanceof Function && !isConstructor ) {
if( events = _class[method].toString().replace(/\n/g,"").match(/(Core\.)?(CatchEvent|CatchRequest)\(([^\)]+)\)/m) ) {
events = events[3].replace(/^[ \t\n\r]*|[ \t\n\r]*$/mg,"").split(/[ \t\n\r]*,[ \t\n\r]*/);
for( var i = 0; i < events.length; i++ ) {
Expand Down Expand Up @@ -739,23 +740,23 @@ if(typeof window != 'undefined') {
FireEvent(new DOM_Init());
}

FireEvent(new DOM_Changed({element: document.body}));
Core.FireEvent(new DOM_Changed({element: document.body}));

window.onscroll = document.body.onscroll = function(event) {
if(old_onscroll) {
old_onscroll(event);
}
FireEvent(new Window_Scroll({dom_event: event}));
Core.FireEvent(new Window_Scroll({dom_event: event}));
};
window.onresize = document.body.onresize = function(event) {
if(old_onresize) {
old_onresize(event);
}
FireEvent(new Window_Resize({dom_event: event}));
Core.FireEvent(new Window_Resize({dom_event: event}));
};

window.onbeforeunload = function(event) {
FireEvent(new DOM_Unload({dom_event: event}));
Core.FireEvent(new DOM_Unload({dom_event: event}));
};

});
Expand Down
23 changes: 23 additions & 0 deletions LICENCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License (MIT)

Copyright (c) 2016 extremeprog-com

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
# CoreJS
Awesome Event Oriented Javascript Framework
# CORE for JS - write code close to how you think

This framework provide us with new principles of the design of the code. The main idea is that the hole project is a set of modules. Every module has it's own objects. Some objects may have Events and Requests.
## Write less, do more

This framework is the simple JS implementation of **CORE design pattern** (acronym: Contexts, Objects, Requests and Events)

This design pattern and the framework provide you ability to easily design and implement well structured, high cohesioned, and low coupled modular systems using Events and Requests. The benefit of that approach is a semantic which is highly close to Business Logic, which allows to write less code doing more, and have less bugs and debugging with it.

The ideas in the base of it are similar to following approaches, and it collects the best benefits of them:

- automata-based programming
- actor model
- system of signals and slots
- event-oriented programming

Event is a complex object, that means that something has already happend.

Request is a complex object, that means that something asks to perform its request.

Other objects of the system can subscribe to Events and Requests. Subscription is a static process.
During initialization Core parses project and subscribes objects on Events and Requests.
Other objects of the system can subscribe to Events and Requests. Subscription is a static process (which is **different** to usual **obj.fire('event')** and **obj.on('event)** dynamic-style subscriptions).

During initialization CORE framework parses the code of methods and subscribes objects on Events and Requests statically.

Note that 99% of real-world cases don't need a dynamic behaviour, which is a good base to simplify this process

Static approach also offers you an ability to build a map how objects/methods are connected, and analyse it, which can extend your Static Code Analysis Tool benefits of your project.

High-level description: https://medium.com/@i_am_os/core-design-pattern-the-way-out-from-overly-complicated-code-b8804449941

How to help the project: https://medium.com/ux-of-programming-languages/lets-build-a-community-around-core-701eb8ebb02c

# Installing

Expand All @@ -16,6 +36,7 @@ During initialization Core parses project and subscribes objects on Events and R
## Events
### Description
There are three steps for using Events: initialization, firing, catching.

You can pass some data with Event.

### Example
Expand All @@ -41,6 +62,7 @@ To fire Event call `FireEvent` function with created Event.

#### Catching
The main twist is that you can catch the fired Event at any spaces of your code.

So this can cut your code several times.

Also you can dinamically subscribe to the event. It is useful in different cases, for example, in angular directives.
Expand All @@ -64,7 +86,7 @@ var GoogleTrackingObject = {
sendPlayerEvents: function() {
var event = CatchEvent(Player_Started, Player_Paused);

ga('send', 'event', 'player', 'player_event');
ga('send', 'event', 'player', 'player_event', event.type);
}
}
```
Expand Down Expand Up @@ -147,6 +169,8 @@ var Player = {

## States

It's an example how we can implement more complicated object's behaviour and use it in CORE-style.

### Description
#### Usage
```javascript
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core-os",
"version": "0.1.5",
"version": "0.1.6",
"homepage": "https://github.com/extremeprog-com/core",
"authors": [
"(Oleg Sergienko <[email protected]>)"
Expand Down
18 changes: 18 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
declare module "core-os";

interface Core {
FireEvent (Request: CoreRequest<string>, success?: Function, fail?: Function) :void;
FireRequest(Event : CoreEvent<string>) :void;

CatchEvent (...args: any): CoreEvent<string>;
CatchRequest(...args: any): CoreRequest<string>;

detachObject (Object: Object): Object;
processObject(Object: Object): Object;
}

declare interface CoreRequest<request> { _request: request, [key: string]: any}
declare interface CoreRequestConstructor<request> { new (parameters?: any): CoreRequest<request>; }

declare interface CoreEvent<event> { _event : event, [key: string]: any}
declare interface CoreEventConstructor<event> { new (parameters?: any): CoreEvent<event>; }
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core-os",
"version": "0.1.5",
"version": "0.1.10",
"description": "Awesome event oriented javascript framework",
"main": "Core.js",
"directories": {
Expand All @@ -9,6 +9,7 @@
"scripts": {
"test": "node ./node_modules/mocha/bin/mocha --opts _tests/mocha.opts"
},
"types": "./index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/extremeprog-com/core.git"
Expand Down

0 comments on commit b78ab90

Please sign in to comment.