mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
ref: better store internal organization
This commit is contained in:
+17
-9
@@ -2,6 +2,10 @@ import { EventBus } from "./event_bus";
|
|||||||
import { Component } from "./component";
|
import { Component } from "./component";
|
||||||
import { shallowEqual } from "./utils";
|
import { shallowEqual } from "./utils";
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Store Definition
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
interface StoreConfig {
|
interface StoreConfig {
|
||||||
env?: any;
|
env?: any;
|
||||||
state?: any;
|
state?: any;
|
||||||
@@ -91,6 +95,9 @@ export class Store extends EventBus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Connect function
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
export function connect(mapStateToProps) {
|
export function connect(mapStateToProps) {
|
||||||
return function(Comp) {
|
return function(Comp) {
|
||||||
return class extends Comp {
|
return class extends Comp {
|
||||||
@@ -137,12 +144,12 @@ export function connect(mapStateToProps) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function _magifyArray({ raw, key, parent, magic, onDirty }) {
|
//------------------------------------------------------------------------------
|
||||||
Object.defineProperty(magic, "length", {
|
// Magic Stuff
|
||||||
get() {
|
//------------------------------------------------------------------------------
|
||||||
return magic.raw.length;
|
|
||||||
}
|
function _magifyArray({ raw, key, parent, onDirty }) {
|
||||||
});
|
let magic = { raw, key, parent, magic: true };
|
||||||
Object.assign(magic, {
|
Object.assign(magic, {
|
||||||
push: function(item) {
|
push: function(item) {
|
||||||
onDirty();
|
onDirty();
|
||||||
@@ -184,6 +191,7 @@ function _magifyArray({ raw, key, parent, magic, onDirty }) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
function magify({ raw, key, parent, onDirty }) {
|
function magify({ raw, key, parent, onDirty }) {
|
||||||
@@ -200,10 +208,10 @@ function magify({ raw, key, parent, onDirty }) {
|
|||||||
if (typeof raw !== "object") {
|
if (typeof raw !== "object") {
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
let magic = { raw, key, parent, magic: true };
|
|
||||||
if (Array.isArray(raw)) {
|
if (Array.isArray(raw)) {
|
||||||
_magifyArray({ raw, key, parent, magic, onDirty });
|
return _magifyArray({ raw, key, parent, onDirty });
|
||||||
} else {
|
} else {
|
||||||
|
let magic = { raw, key, parent, magic: true };
|
||||||
Object.keys(raw).forEach(propKey => {
|
Object.keys(raw).forEach(propKey => {
|
||||||
let prop = magify({
|
let prop = magify({
|
||||||
raw: raw[propKey],
|
raw: raw[propKey],
|
||||||
@@ -223,6 +231,6 @@ function magify({ raw, key, parent, onDirty }) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return magic;
|
||||||
}
|
}
|
||||||
return magic;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user