-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for privatenumber/tsx#38 But also, it's time for those to be TypeScript Note, I added `// @ts-nocheck` to the top of the files to suppress TypeScript errors for now, but this should be removed once we move way from Backbone
- Loading branch information
1 parent
353a0ea
commit a3b51f7
Showing
4 changed files
with
58 additions
and
39 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
specifyweb/frontend/js_src/lib/components/DataModel/backbone.js
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
specifyweb/frontend/js_src/lib/components/DataModel/backbone.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// @ts-nocheck | ||
|
||
import BackboneBase from 'backbone'; | ||
import $ from 'jquery'; | ||
import _ from 'underscore'; | ||
|
||
// REFACTOR: remove @ts-nocheck | ||
|
||
// https://stackoverflow.com/questions/14866014/debugging-javascript-backbone-and-marionette | ||
|
||
function createNamedConstructor(name, constructor) { | ||
const function_ = new Function( | ||
'constructor', | ||
`return function ${name} () {\n` + | ||
` // wrapper function created dynamically for "${name}"\n` + | ||
` // constructor to allow instances to be identified in the debugger\n` + | ||
` constructor.apply(this, arguments);\n` + | ||
`};` | ||
); | ||
return function_(constructor); | ||
} | ||
|
||
const originalExtend = BackboneBase.View.extend; | ||
const nameProperty = '__name__'; | ||
const newExtend = function (protoProps, classProps) { | ||
if (protoProps && protoProps.hasOwnProperty(nameProperty)) { | ||
// BUG: check that name is a valid identifier | ||
const name = protoProps[nameProperty]; | ||
// Wrap constructor from protoProps if supplied or 'this' (thi function we are extending) | ||
const constructor = protoProps.hasOwnProperty('constructor') | ||
? protoProps.constructor | ||
: this; | ||
protoProps = _.extend(protoProps, { | ||
constructor: createNamedConstructor(name, constructor), | ||
}); | ||
} else { | ||
console.warn('Creating backbone subclass without __name__ property.'); | ||
} | ||
return originalExtend.call(this, protoProps, classProps); | ||
}; | ||
|
||
BackboneBase.Model.extend = | ||
BackboneBase.Collection.extend = | ||
BackboneBase.Router.extend = | ||
BackboneBase.View.extend = | ||
newExtend; | ||
|
||
BackboneBase.$ = $; | ||
|
||
export { default as Backbone } from 'backbone'; |
5 changes: 4 additions & 1 deletion
5
...lib/components/DataModel/collectionApi.js → ...lib/components/DataModel/collectionApi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters