-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(core): supports effect action supports effect action and change interceptor to middleware * test: rewrite some test with react-hooks-testing-library * chore: remove unexpect adding dependency * feat: use the method's name as the default effect key * fix: eslint * docs: update README
- Loading branch information
Showing
37 changed files
with
514 additions
and
624 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ export class TodoService { | |
state: 'todo', | ||
}, | ||
]); | ||
}, 1); | ||
}, 1000); | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
export function boundMethod( | ||
target: Function, | ||
key: string | number | symbol, | ||
descriptor: PropertyDescriptor, | ||
) { | ||
let fn = descriptor.value; | ||
|
||
if (typeof fn !== 'function') { | ||
throw new TypeError( | ||
`@boundMethod decorator can only be applied to methods not: ${typeof fn}`, | ||
); | ||
} | ||
|
||
// In IE11 calling Object.defineProperty has a side-effect of evaluating the | ||
// getter for the property which is being replaced. This causes infinite | ||
// recursion and an "Out of stack space" error. | ||
let definingProperty = false; | ||
|
||
return { | ||
configurable: true, | ||
get() { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if ( | ||
definingProperty || | ||
this === target.prototype || | ||
Object.hasOwnProperty.call(this, key) || | ||
typeof fn !== 'function' | ||
) { | ||
return fn; | ||
} | ||
|
||
const boundFn = fn.bind(this); | ||
definingProperty = true; | ||
Object.defineProperty(this, key, { | ||
configurable: true, | ||
get() { | ||
return boundFn; | ||
}, | ||
set(value) { | ||
fn = value; | ||
delete this[key]; | ||
}, | ||
}); | ||
definingProperty = false; | ||
return boundFn; | ||
}, | ||
set(value: unknown) { | ||
fn = value; | ||
}, | ||
}; | ||
} | ||
|
||
export function boundClass(target: Function) { | ||
// (Using reflect to get all keys including symbols) | ||
let keys: Array<string | symbol | number>; | ||
// Use Reflect if exists | ||
if (typeof Reflect !== 'undefined' && typeof Reflect.ownKeys === 'function') { | ||
keys = Reflect.ownKeys(target.prototype); | ||
} else { | ||
keys = Object.getOwnPropertyNames(target.prototype); | ||
// Use symbols if support is provided | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
keys = keys.concat(Object.getOwnPropertySymbols(target.prototype)); | ||
} | ||
} | ||
|
||
keys.forEach(key => { | ||
// Ignore special case target method | ||
if (key === 'constructor') { | ||
return; | ||
} | ||
|
||
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, key); | ||
|
||
// Only methods need binding | ||
if (descriptor !== undefined && typeof descriptor.value === 'function') { | ||
Object.defineProperty( | ||
target.prototype, | ||
key, | ||
boundMethod(target, key, descriptor), | ||
); | ||
} | ||
}); | ||
return target; | ||
} |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
export enum EffectEventType { | ||
StateChanged = 'StateChanged', | ||
EffectAction = 'EffectAction', | ||
} | ||
|
||
export class EffectEvent<Bean = unknown, Value = unknown> { | ||
constructor( | ||
readonly target: Bean, | ||
readonly type: EffectEventType, | ||
readonly name: string | symbol, | ||
readonly value: Value, | ||
) { | ||
this.target = target; | ||
this.type = type; | ||
this.name = name; | ||
this.value = value; | ||
} | ||
} |
Oops, something went wrong.