From f97486cd4741273b3e869ebc4f34af261eac4ff7 Mon Sep 17 00:00:00 2001 From: Alex Murzina Date: Tue, 30 Jul 2019 10:40:22 +1000 Subject: [PATCH] Added a special check to the processObject method to make sure it does not process constructor methods which is an issue --- .gitignore | 3 ++- CHANGELOG.md | 10 ++++++++++ Core.js | 3 ++- LICENCE.txt | 23 +++++++++++++++++++++++ index.d.ts | 6 +++--- 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 LICENCE.txt diff --git a/.gitignore b/.gitignore index 2144dcd..fbcb2ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ .DS_Store -.package.json.swp \ No newline at end of file +.package.json.swp +*.iml \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..be26d74 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +### 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. \ No newline at end of file diff --git a/Core.js b/Core.js index 6ce6248..82d1f8f 100644 --- a/Core.js +++ b/Core.js @@ -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++ ) { diff --git a/LICENCE.txt b/LICENCE.txt new file mode 100644 index 0000000..051a4e1 --- /dev/null +++ b/LICENCE.txt @@ -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. \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 9958299..5dbd4f9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,12 +4,12 @@ interface Core { FireEvent (Request: CoreRequest, success?: Function, fail?: Function) :void; FireRequest(Event : CoreEvent) :void; - CatchEvent(...args: any) : CoreRequest; + CatchEvent (...args: any): CoreEvent; CatchRequest(...args: any): CoreRequest; detachObject (Object: Object): Object; processObject(Object: Object): Object; } -declare type CoreRequest = { _request: string } & {[key: string]: any}; -declare type CoreEvent = { _event : string } & {[key: string]: any}; \ No newline at end of file +declare interface CoreRequest { _request: string, [key: string]: any} +declare interface CoreEvent { _event : string, [key: string]: any} \ No newline at end of file