LinearGradient{Fill} and RadialGradient{Fill}

If you want to import these classes to do things like

node.fill instanceof LinearGradient

you have to drop the “Fill” suffix. The class creation functions are indeed called

LinearGradientFill
RadialGradientFill

which is confusing. Perhaps the names exported from scenegraph should be fixed? Or augmented (so it won’t break existing code)?

I console-log’d the results of webpack loading the scenegraph module, and here’s the relevant portion:

RepeatGrid: { [Function: RepeatGrid] super_: [Function: SceneNode] },
SymbolInstance: { [Function: SymbolInstance] super_: [Function: SceneNode] },
LinkedGraphic: { [Function: LinkedGraphic] super_: [Function: SceneNode] },
Matrix: { [Function: Matrix] newFromString: [Function] },
Color: { [Function: Color] deserializeAGC: [Function] },
LinearGradient: [Function: LinearGradientFill],
RadialGradient: [Function: RadialGradientFill],
ImageFill: { [Function: ImageFill] SCALE_COVER: 'cover', SCALE_STRETCH: 'normal' },
Blur: { [Function: Blur] deserializeAGC: [Function] },
Shadow: { [Function: Shadow] deserializeAGC: [Function], deserialize: [Function] },

in which case you can see that only these two module exports don’t match the function (class) names.

Just in case:

Sorry if I missed something.

Thanks, good to know it’s been spotted before.

I just want to draw a bit more attention as it’s old problem with breaking fix. Now there are 2 ways to define what fill is used. It’s either:

  • more obvious: usage of instanceof with not documented (fill instanceof LineatGradient) class name or…
  • more tricky: check constructor name and compare with documented class name (consturctor.name === 'LineatGradientFill').

Any fix will break one of the way used in the plugins.

They could also add the correct aliases for the same names in the module export. Nothing breaks, and then instance of LinearGradientFill, etc., starts working.

2 Likes

Agreed, although I wouldn’t like that as a long-term solution. Maybe add an alias for a few versions, mark it as deprecated to give us time to adjust plugins and then remove the alias, leaving the “real” thing (whatever that is) there.

1 Like

Are there any notifications for developers to let them know that plugin will stop working in couple versions?

Agreed this is a confusing point. @peterflynn is this something we can fix soon?