Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace can.Model with CanModel #2

Open
ccummings opened this issue Mar 19, 2017 · 3 comments
Open

Replace can.Model with CanModel #2

ccummings opened this issue Mar 19, 2017 · 3 comments
Assignees

Comments

@ccummings
Copy link
Contributor

No description provided.

@bgando
Copy link
Contributor

bgando commented Jul 7, 2017

Replace can.Model with CanModel

My understanding is that this codemod should perform the following transformation:

---------|----------- 2.x ------------|---------------------- 3.0 -------------------------------
require | var can = require("can"); | var canModel = require("can-connect/can/model/model");
usage | can.Model.extend({ ... }); | canModel.extend({ ... });

How should this codemod handle this if it is deprecated in 3.0?

Can Model in 3.0
"However, use of can.Model will be deprecated in CanJS 3.0. Instead of extending can.Model, extend can-map and can-list and use the can-connect/can/map/map behavior to connect your Map and List to a connection"

Edge Cases

Is there anything I should keep in mind?

/cc @chasenlehara @justinbmeyer - let me know if I'm on the right track and how to handle a feature that is deprecated.

@justinbmeyer
Copy link
Contributor

justinbmeyer commented Jul 7, 2017

var Todo = can.Model.extend({
  id: "_ID",
  findAll: X1,
  findOne: X2,
  create: X3,
  update: X4,
  destroy: X5,
  parseModels: PMPROP
},PROTOTYPE_OBJECT);
var connectBaseMap = require("can-connect/can/base-map/base-map");
var CanMap = require("can-map");
var set = require("can-set");

var Todo = CanMap.extend(PROTOTYPE_OBJECT);

Todo.algebra = new set.Algebra(
  set.props.id("_ID")
);

connectBaseMap({
  Map: Todo,
  url: {
    getListData: X1,
    getData: X2,
    createData, updateData, destroyData
  },
  algebra: Todo.algebra,
  parseListProp: PMPROP
});
can-connect/can/base-map/base-map");
var DefineMap = require("can-define/map/map");

var constructor = require("can-connect/constructor/constructor");
var canMap = require("../map/map");
var canRef = require("../ref/ref");
var constructorStore = require("../../constructor/store/store");
var dataCallbacks = require("../../data/callbacks/callbacks");
var callbacksCache = require("../../data/callbacks-cache/callbacks-cache");
var dataParse = require("../../data/parse/parse");
var dataUrl = require("../../data/url/url");
var callbacksOnce = require("../../constructor/callbacks-once/callbacks-once");
var GLOBAL = require("can-util/js/global/global");;

var Todo = DefineMap.extend(PROTOTYPE_OBJECT);

connect([
            constructor,
		canMap,
		canRef,
		constructorStore,
		dataCallbacks,
		dataParse,
		dataUrl,
		callbacksOnce

],{
  Map: Todo,
  url: {
    getListData: X1,
    getData: X2,
    createData, updateData, destroyData
  }
});

@bmomberger-bitovi
Copy link

One edge case: can.Model.extend() in 2.x would add the model class to the global namespace if you gave it a string as the first argument (in fact, all can.Constructs did this). In 3.0 this no longer happens, so old code that expects Maps/Models/Constructs to be on the global namespace will break. Does codemods support flags? We could support an optional --globalize-classes:

can.X1.extend(X2, ...);
var GLOBAL = require("can-util/js/global/global");
var set = require("can-util/js/set/set");

set(GLOBAL(), X2, can.X1.extend(X2, ...));

@bgando bgando removed their assignment Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants