Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
1.0.3 release - bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
szympajka committed Feb 24, 2019
1 parent aff0df5 commit 1ca0812
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 150 deletions.
23 changes: 0 additions & 23 deletions modules/component-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ const actions = (viewObject) => {
const getState = () => viewObject.actions.state;

const setState = async (newState = {}, callback = null, updateView = true) => {
console.log('Setting new state...');

let state = newState;
let shouldComponentUpdate = true;

Expand All @@ -98,7 +96,6 @@ const actions = (viewObject) => {

viewObject.actions.state = defaultsDeepPreserveArrays(state, viewObject.actions.state);

console.log('shouldComponentUpdate');
if (isFunction(viewObject.actions.shouldComponentUpdate)) {
shouldComponentUpdate = await !!viewObject.actions.shouldComponentUpdate(viewObject.actions.state, viewObject.actions);
} else {
Expand All @@ -107,14 +104,12 @@ const actions = (viewObject) => {

if (shouldComponentUpdate) {
if (updateView) {
console.log('componentWillUpdate');
if (viewObject.actions.componentWillUpdate && isFunction(viewObject.actions.componentWillUpdate)) {
await viewObject.actions.componentWillUpdate(viewObject.actions.state, viewObject.actions, viewObject);
}

viewObject.nodes.view = patch(viewObject.nodes.view, viewObject.component.getViewComponent(viewObject.actions.state));

console.log('componentDidUpdate');
if (viewObject.actions.componentDidUpdate && isFunction(viewObject.actions.componentDidUpdate)) {
await viewObject.actions.componentDidUpdate(viewObject.actions.state, viewObject.actions);
}
Expand Down Expand Up @@ -149,8 +144,6 @@ const actions = (viewObject) => {

return result;
});
} else {
console.error('Please provide reducer function to use this functionality!');
}
};

Expand Down Expand Up @@ -195,8 +188,6 @@ const actions = (viewObject) => {

const componentFn = (viewObject) => {
const getViewComponent = (newState) => {
console.log('Getting view...');

if (viewObject.actions.render && isFunction(viewObject.actions.render)) {
let node = null;

Expand All @@ -213,14 +204,10 @@ const componentFn = (viewObject) => {
};

const getViewContext = () => {
console.log('Finding view context...');

if (viewObject.actions.spinner) {
console.log('View context found: Spinner');
return loader(viewObject.actions);
}

console.log('View context found: `render()` result');
return getViewComponent(viewObject.actions.state);
};

Expand Down Expand Up @@ -338,7 +325,6 @@ const createAsyncComponent = async (params = defaultParams) => {
}

if (params.componentWillCreateViewObject && isFunction(params.componentWillCreateViewObject)) {
console.log('componentWillCreateViewObject');
params.componentWillCreateViewObject(params.state);
}

Expand All @@ -356,7 +342,6 @@ const createAsyncComponent = async (params = defaultParams) => {
viewObject.component = componentFn(viewObject);

if (viewObject.actions.componentWillInit && isFunction(viewObject.actions.componentWillInit)) {
console.log('componentWillInit');
viewObject.actions.componentWillInit(viewObject.actions.state, viewObject.actions);
}

Expand All @@ -369,43 +354,36 @@ const createAsyncComponent = async (params = defaultParams) => {
...viewObject.nodes.view.data,
hook: {
init: () => {
console.log('init');
if (viewObject.actions.componentDidInit && isFunction(viewObject.actions.componentDidInit)) {
viewObject.actions.componentDidInit(viewObject.actions.state, viewObject.actions);
}
},
create: () => {
console.log('componentWillMount');
if (viewObject.actions.componentWillMount && isFunction(viewObject.actions.componentWillMount)) {
viewObject.actions.componentWillMount(viewObject.actions.state, viewObject.actions);
}
},
prepatch: () => {
console.log('prepatch');
if (viewObject.actions.componentWillPrepatch && isFunction(viewObject.actions.componentWillPrepatch)) {
viewObject.actions.componentWillPrepatch(viewObject.actions.state, viewObject.actions);
}
},
postpatch: () => {
console.log('postpatch');
if (viewObject.actions.componentWillPostpatch && isFunction(viewObject.actions.componentWillPostpatch)) {
viewObject.actions.componentWillPostpatch(viewObject.actions.state, viewObject.actions);
}
},
insert: () => {
console.log('componentDidMount');
if (viewObject.actions.componentDidMount && isFunction(viewObject.actions.componentDidMount)) {
viewObject.actions.componentDidMount(viewObject.actions.state, viewObject.actions);
}
},
destroy: () => {
console.log('componentWillUnmount');
if (viewObject.actions.componentWillUnmount && isFunction(viewObject.actions.componentWillUnmount)) {
viewObject.actions.componentWillUnmount(viewObject.actions.state, viewObject.actions);
}
},
remove: (vnode, removeCallback) => {
console.log('componentDidUnmount');
if (viewObject.actions.componentDidUnmount && isFunction(viewObject.actions.componentDidUnmount)) {
viewObject.actions.componentDidUnmount(viewObject.actions.state, viewObject.actions);
}
Expand All @@ -416,7 +394,6 @@ const createAsyncComponent = async (params = defaultParams) => {
};

if (viewObject.actions.componentDidCreateViewObject && isFunction(viewObject.actions.componentDidCreateViewObject)) {
console.log('componentDidCreateViewObject');
viewObject.actions.componentDidCreateViewObject(viewObject.actions.state, viewObject.actions);
}

Expand Down
26 changes: 1 addition & 25 deletions modules/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const actions = (viewObject) => {
const getState = () => viewObject.actions.state;

const setState = (newState = {}, callback = null, updateView = true) => {
console.log('Setting new state...');

let state = newState;
let shouldComponentUpdate = true;

Expand All @@ -63,7 +61,6 @@ const actions = (viewObject) => {

viewObject.actions.state = defaultsDeepPreserveArrays(state, viewObject.actions.state);

console.log('shouldComponentUpdate');
if (isFunction(viewObject.actions.shouldComponentUpdate)) {
shouldComponentUpdate = !!viewObject.actions.shouldComponentUpdate(viewObject.actions.state, viewObject.actions);
} else {
Expand All @@ -72,7 +69,6 @@ const actions = (viewObject) => {

if (shouldComponentUpdate) {
if (updateView) {
console.log('componentWillUpdate');
if (viewObject.actions.componentWillUpdate) {
if (isFunction(viewObject.actions.componentWillUpdate)) {
viewObject.actions.componentWillUpdate(viewObject.actions.state, viewObject.actions, viewObject);
Expand All @@ -81,7 +77,6 @@ const actions = (viewObject) => {

viewObject.nodes.view = patch(viewObject.nodes.view, viewObject.component.getViewComponent(viewObject.actions.state));

console.log('componentDidUpdate');
if (viewObject.actions.componentDidUpdate) {
if (isFunction(viewObject.actions.componentDidUpdate)) {
viewObject.actions.componentDidUpdate(viewObject.actions.state, viewObject.actions);
Expand Down Expand Up @@ -116,8 +111,6 @@ const actions = (viewObject) => {

return viewObject.actions.reducer(prevState, nextAction, viewObject.actions);
});
} else {
console.error('Please provide reducer function to use this functionality!');
}
};

Expand Down Expand Up @@ -159,8 +152,6 @@ const actions = (viewObject) => {

const componentFn = (viewObject) => {
const getViewComponent = (newState) => {
console.log('Getting view...');

if (viewObject.actions.render && isFunction(viewObject.actions.render)) {
let node = null;

Expand All @@ -176,12 +167,7 @@ const componentFn = (viewObject) => {
return h('div', 'Nothing to render');
};

const getViewContext = () => {
console.log('Finding view context...');

console.log('View context found: `render()` result');
return getViewComponent(viewObject.actions.state);
};
const getViewContext = () => getViewComponent(viewObject.actions.state);

const profileHook = (hook) => {
const types = uniq(map(hook, (hk) => {
Expand Down Expand Up @@ -295,7 +281,6 @@ const createComponent = (params = defaultParams) => {
params.state = isFunction(params.state) ? params.state(params) : params.state;

if (params.componentWillCreateViewObject && isFunction(params.componentWillCreateViewObject)) {
console.log('componentWillCreateViewObject');
params.componentWillCreateViewObject(params.state);
}

Expand All @@ -313,7 +298,6 @@ const createComponent = (params = defaultParams) => {
viewObject.component = componentFn(viewObject);

if (viewObject.actions.componentWillInit && isFunction(viewObject.actions.componentWillInit)) {
console.log('componentWillInit');
viewObject.actions.componentWillInit(viewObject.actions.state, viewObject.actions);
}

Expand All @@ -326,43 +310,36 @@ const createComponent = (params = defaultParams) => {
...viewObject.nodes.view.data,
hook: {
init: () => {
console.log('init');
if (viewObject.actions.componentDidInit && isFunction(viewObject.actions.componentDidInit)) {
viewObject.actions.componentDidInit(viewObject.actions.state, viewObject.actions);
}
},
create: () => {
console.log('componentWillMount');
if (viewObject.actions.componentWillMount && isFunction(viewObject.actions.componentWillMount)) {
viewObject.actions.componentWillMount(viewObject.actions.state, viewObject.actions);
}
},
prepatch: () => {
console.log('prepatch');
if (viewObject.actions.componentWillPrepatch && isFunction(viewObject.actions.componentWillPrepatch)) {
viewObject.actions.componentWillPrepatch(viewObject.actions.state, viewObject.actions);
}
},
postpatch: () => {
console.log('postpatch');
if (viewObject.actions.componentWillPostpatch && isFunction(viewObject.actions.componentWillPostpatch)) {
viewObject.actions.componentWillPostpatch(viewObject.actions.state, viewObject.actions);
}
},
insert: () => {
console.log('componentDidMount');
if (viewObject.actions.componentDidMount && isFunction(viewObject.actions.componentDidMount)) {
viewObject.actions.componentDidMount(viewObject.actions.state, viewObject.actions);
}
},
destroy: () => {
console.log('componentWillUnmount');
if (viewObject.actions.componentWillUnmount && isFunction(viewObject.actions.componentWillUnmount)) {
viewObject.actions.componentWillUnmount(viewObject.actions.state, viewObject.actions);
}
},
remove: (vnode, removeCallback) => {
console.log('componentDidUnmount');
if (viewObject.actions.componentDidUnmount && isFunction(viewObject.actions.componentDidUnmount)) {
viewObject.actions.componentDidUnmount(viewObject.actions.state, viewObject.actions);
}
Expand All @@ -373,7 +350,6 @@ const createComponent = (params = defaultParams) => {
};

if (viewObject.actions.componentDidCreateViewObject && isFunction(viewObject.actions.componentDidCreateViewObject)) {
console.log('componentDidCreateViewObject');
viewObject.actions.componentDidCreateViewObject(viewObject.actions.state, viewObject.actions);
}

Expand Down
12 changes: 7 additions & 5 deletions modules/styled.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ####### Declarations ##########
const h = require('../vendors/snabbdom/h.js');
const cssToJS = require('../utils/cssToJS.js');
const { forEach, has, filter } = require('lodash');
const { forEach, has, filter, defaultsDeep } = require('lodash');
const { mergeWithFn, ss } = require('../utils/helpers.js');
const { isDefinedChild } = require('../utils/vDomHelpers.js');

Expand All @@ -19,21 +19,23 @@ const defaultData = {
};

// ####### Helpers ##########
const getVNode = (sel = 'div', literals, ...expressions) => (d = { ...defaultData }, c) => {
const getVNode = (sel = 'div', literals, ...expressions) => (d = defaultData, c) => {
let data = d;
let children = c;

if (!children && isDefinedChild(data)) {
children = data;
data = { ...defaultData };
} else {
data = { ...defaultData, ...data };
data = defaultsDeep(data, defaultData);
}

const props = data.styled;

const style = cssWithProps(props, data)(literals, ...expressions);
const defprops = { style, styledProps: { css: cssWithPropsPlain(props, data)(literals, ...expressions) } };
const css = cssWithPropsPlain(props, data)(literals, ...expressions);
const style = cssToJS(css);

const defprops = { style, styledProps: { css } };

return h(sel, mergeWithFn(defprops, data), filter(children, child => isDefinedChild(child)));
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snabbdom-react-components",
"version": "1.0.2",
"version": "1.0.3",
"description": "React like, Snabbdom based, Virtual Dom framework for JavaScript Web Applications",
"keywords": [
"React",
Expand Down
Loading

0 comments on commit 1ca0812

Please sign in to comment.