Skip to content

Commit

Permalink
Add support for Ember 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jan 27, 2019
1 parent 2d1ff0c commit 5df19bc
Showing 1 changed file with 82 additions and 65 deletions.
147 changes: 82 additions & 65 deletions vendor/ember-modifier-manager-polyfill.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals Ember */
/* eslint-disable ember/new-module-imports */

import { gte } from 'ember-compatibility-helpers';
import { lte, gte } from 'ember-compatibility-helpers';

(() => {
'use strict';
Expand Down Expand Up @@ -56,79 +56,76 @@ import { gte } from 'ember-compatibility-helpers';
let compileTimeLookup = compiler.resolver;
let runtimeResolver = compileTimeLookup.resolver;

let CustomModifierDefinition;
if (gte('3.6.0-alpha.1')) {
class CustomModifierState {
constructor(element, delegate, modifier, args) {
this.element = element;
this.delegate = delegate;
this.modifier = modifier;
this.args = args;
}
class CustomModifierState {
constructor(element, delegate, modifier, args) {
this.element = element;
this.delegate = delegate;
this.modifier = modifier;
this.args = args;
}

destroy() {
const { delegate, modifier, args } = this;
let modifierArgs = valueForCapturedArgs(args);
delegate.destroyModifier(modifier, modifierArgs);
}
destroy() {
const { delegate, modifier, args } = this;
let modifierArgs = valueForCapturedArgs(args);
delegate.destroyModifier(modifier, modifierArgs);
}
}

class Polyfilled_CustomModifierManager {
//create(element: Simple.Element, state: ModifierDefinitionState, args: IArguments, dynamicScope: DynamicScope, dom: DOMChanges): ModifierInstanceState;
create(element, definition, args) {
const capturedArgs = args.capture();
let modifierArgs = valueForCapturedArgs(capturedArgs);
let instance = definition.delegate.createModifier(
definition.ModifierClass,
modifierArgs
);

return new CustomModifierState(
element,
definition.delegate,
instance,
capturedArgs
);
}
class Polyfilled_CustomModifierManager {
//create(element: Simple.Element, state: ModifierDefinitionState, args: IArguments, dynamicScope: DynamicScope, dom: DOMChanges): ModifierInstanceState;
create(element, definition, args) {
const capturedArgs = args.capture();
let modifierArgs = valueForCapturedArgs(capturedArgs);
let instance = definition.delegate.createModifier(
definition.ModifierClass,
modifierArgs
);

return new CustomModifierState(element, definition.delegate, instance, capturedArgs);
}

//getTag(modifier: ModifierInstanceState): Tag;
getTag({ args }) {
return args.tag;
}
//getTag(modifier: ModifierInstanceState): Tag;
getTag({ args }) {
return args.tag;
}

//install(modifier: ModifierInstanceState): void;
install(state) {
let { element, args, delegate, modifier } = state;
let modifierArgs = valueForCapturedArgs(args);
delegate.installModifier(modifier, element, modifierArgs);
}
//install(modifier: ModifierInstanceState): void;
install(state) {
let { element, args, delegate, modifier } = state;
let modifierArgs = valueForCapturedArgs(args);
delegate.installModifier(modifier, element, modifierArgs);
}

//update(modifier: ModifierInstanceState): void;
update(state) {
let { args, delegate, modifier } = state;
let modifierArgs = valueForCapturedArgs(args);
delegate.updateModifier(modifier, modifierArgs);
}
//update(modifier: ModifierInstanceState): void;
update(state) {
let { args, delegate, modifier } = state;
let modifierArgs = valueForCapturedArgs(args);
delegate.updateModifier(modifier, modifierArgs);
}

//getDestructor(modifier: ModifierInstanceState): Option<Destroyable>;
getDestructor(state) {
return state;
}
//getDestructor(modifier: ModifierInstanceState): Option<Destroyable>;
getDestructor(state) {
return state;
}
}

CustomModifierDefinition = class Polyfilled_CustomModifierDefinition {
constructor(name, ModifierClass, delegate) {
this.name = name;
this.state = {
ModifierClass,
name,
delegate,
};
this.manager = new Polyfilled_CustomModifierManager();
}
class Polyfilled_CustomModifierDefinition {
constructor(name, ModifierClass, delegate) {
this.name = name;
this.state = {
ModifierClass,
name,
delegate,
};
this.manager = new Polyfilled_CustomModifierManager();
}
}

// meta was not passed to `_lookupModifier` until 3.7
if (lte('3.7.0-alpha.1')) {
runtimeResolver.lookupModifier = function(name, meta) {
return this.handle(this._lookupModifier(name, meta));
};
} else {
// TODO: rwjblue implement 3.1 - 3.5
}

runtimeResolver._lookupModifier = function(name, meta) {
Expand All @@ -141,7 +138,27 @@ import { gte } from 'ember-compatibility-helpers';
let managerFactory = getModifierManager(modifier.class);
let manager = managerFactory(owner);

return new CustomModifierDefinition(name, modifier.class, manager);
if (gte('3.6.0-alpha.1')) {
return new Polyfilled_CustomModifierDefinition(name, modifier.class, manager);
} else {
class Polyfilled_CustomModifierManagerLt36 extends Polyfilled_CustomModifierManager {
constructor(name, ModifierClass, manager) {
super();

this.state = {
ModifierClass,
delegate: manager,
};
}

// create(element: Simple.Element, args: Arguments, _dynamicScope: DynamicScope, dom: any) {
create(element, args) {
return super.create(element, this.state, args);
}
}

return new Polyfilled_CustomModifierManagerLt36(name, modifier.class, manager);
}
}
}

Expand Down

0 comments on commit 5df19bc

Please sign in to comment.